gpt4 book ai didi

c++ - Infile 不完整类型错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:06:34 24 4
gpt4 key购买 nike

我正在构建一个接受这种格式的输入文件的程序:

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<<")";
}

最佳答案

文件流在 header <fstream> 中定义而你不包括它。

你应该添加:

#include <fstream>

关于c++ - Infile 不完整类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com