我建立一个程序,需要输入文件格式如下:INFILE不完全类型错误
title author
title author
etc
and outputs to screen
title (author)
title (author)
etc
我目前得到的问题是一个错误:
"ifstream infile has incomplete type and cannot be defined"
以下是节目:
#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<<")";
}
可能重复http://stackoverflow.com/questions/1057287/offstream-error-in-c – Vaibhav 2012-03-22 05:36:56
有没有这样的标准包括文件作为''。你的编译器应该显示一个错误。如果没有,请检查其选项。在这种情况下,您*确实希望发生错误。 –
atzz
2012-03-22 08:21:53