我建立一個程序,需要輸入文件格式如下: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