本文介绍了INFILE不完全类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我建立一个程序,它的输入文件格式如下:
标题作者标题作者等等并输出到屏幕标题(作者)标题(作者)等等我目前得到的问题是一个错误:
的ifstream infile中具有不完整的类型,不能被定义为
以下是该程序:
的#include<&iostream的GT;#包括LT&;串GT;#包括LT&;&ifstream的GT;使用命名空间std;串BOOKTITLE [14];串BOOKAUTHOR [14];INT loadData(字符串路径名);无效SHOWALL(INT计数器);诠释的main(){INT计数器;字符串路径;COUT&所述;&下;输入要访问的文件的名称:;CIN>>路径;loadData(路径);SHOWALL(柜);}INT loadData(字符串路径名)//从加载数据infile中放入数组中{ ifstream的INFILE; INT计数器= 0; infile.open(路径); //打开从主用户输入文件 如果(infile.fail()) { COUT<< 文件打开失败; 返回0; } 而(!infile.eof()) { INFILE>> BOOKTITLE [14]; //获取输入并投入平行阵列 INFILE>> BOOKAUTHOR [14]; 反++; } infile.close;}无效SHOWALL(INT计数器)//显示标题(作者)格式的输入{ COUT&所述;&所述; BOOKTITLE&所述;&下;(&所述;&所述; BOOKAUTHOR&所述;&下;);}解决方案
文件流定义在头文件< fstream的方式> ,你是不是包括它
您应该加上:
的#include<&的fstream GT;I am building a program that takes an input file in this format:
title author title author etc and outputs to screen title (author) title (author) etcThe Problem I am currently getting is a error:
"ifstream infile has incomplete type and cannot be defined"
Following is the program:
#include <iostream> #include <string> #include <ifstream> using namespace std; string bookTitle [14]; string bookAuthor [14]; int loadData (string pathname); void showall (int counter); int main () { int counter; string pathname; cout<<"Input the name of the file to be accessed: "; cin>>pathname; loadData (pathname); showall (counter); } int loadData (string pathname) // Loads data from infile into arrays { ifstream infile; int counter = 0; infile.open(pathname); //Opens file from user input in main if( infile.fail() ) { cout << "File failed to open"; return 0; } while (!infile.eof()) { infile >> bookTitle [14]; //takes input and puts into parallel arrays infile >> bookAuthor [14]; counter++; } infile.close; } void showall (int counter) // shows input in title(author) format { cout<<bookTitle<<"("<<bookAuthor<<")"; }解决方案
File streams are defined in the header <fstream> and you are not including it.
You should add:
#include <fstream>
更多推荐
INFILE不完全类型错误
发布评论