c – Infile不完整类型错误

前端之家收集整理的这篇文章主要介绍了c – 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<<")";
}

解决方法

文件流在标题< fstream>中定义.而且你不包括它.

你应该添加

#include <fstream>
原文链接:https://www.f2er.com/c/117449.html

猜你在找的C&C++相关文章