C++ 填充不完整类型错误
我正在构建一个以以下格式获取输入文件的程序:C++ 填充不完整类型错误,c++,arrays,function,file-io,C++,Arrays,Function,File Io,我正在构建一个以以下格式获取输入文件的程序: title author title author etc and outputs to screen title (author) title (author) etc 我当前遇到的问题是一个错误: “ifstream infle的类型不完整,无法定义” 节目如下: #include <iostream> #include <string> #include <ifstrea
title author
title author
etc
and outputs to screen
title (author)
title (author)
etc
我当前遇到的问题是一个错误:
“ifstream infle的类型不完整,无法定义”
节目如下:
#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<<")";
}
#包括
#包括
#包括
使用名称空间std;
字符串书名[14];
字符串图书作者[14];
int loadData(字符串路径名);
void showall(整数计数器);
int main()
{
整数计数器;
字符串路径名;
coutpathname;
加载数据(路径名);
showall(柜台);
}
int loadData(字符串路径名)//将数据从infle加载到数组中
{
河流充填;
int计数器=0;
infle.open(路径名);//从主目录中的用户输入打开文件
if(infle.fail())
{
cout>bookTitle[14];//接受输入并放入并行数组
内嵌>>书籍作者[14];
计数器++;
}
e.关闭;
}
void showall(int计数器)//以标题(作者)格式显示输入
{
cout文件流在头文件
中定义,您不包括它
您应该添加:
#include <fstream>
#包括
这是我的代码,之前的错误已经修复,现在我遇到了一个问题,输入文本文件名后程序崩溃
#include <iostream>
#include <string>
#include <fstream>
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
{
fstream infile;
int counter = 0;
infile.open(pathname.c_str()); //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<<")";
}
#包括
#包括
#包括
使用名称空间std;
字符串书名[14];
字符串图书作者[14];
int loadData(字符串路径名);
void showall(整数计数器);
int main()
{
整数计数器;
字符串路径名;
coutpathname;
加载数据(路径名);
showall(柜台);
}
int loadData(字符串路径名)//将数据从infle加载到数组中
{
河道充填;
int计数器=0;
infle.open(pathname.c_str());//从main中的用户输入打开文件
if(infle.fail())
{
cout>bookTitle[14];//接受输入并放入并行数组
内嵌>>书籍作者[14];
计数器++;
}
infle.close();
}
void showall(int计数器)//以标题(作者)格式显示输入
{
coutPossible duplicate没有像
这样的标准include文件。您的编译器应该显示错误。如果没有,请检查其选项。您确实希望在这种情况下出现错误。我得到的新错误是:没有匹配的函数调用“std::basic\u ifstream::open(std::string&)”