Infile incomplete type error

Posted by kd7vdb on Stack Overflow See other posts from Stack Overflow or by kd7vdb
Published on 2012-03-22T05:24:27Z Indexed on 2012/03/22 5:30 UTC
Read the original article Hit count: 167

Filed under:
|
|
|

I am building a program that takes a input file in this format:

title author

title author

etc

and outputs to screen

title (author)

title (author)

etc

The Problem I am currently getting is a error "ifstream infile has incomplee 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<<")";







}

Thanks ahead of time,

kd7vdb

© Stack Overflow or respective owner

Related posts about c++

Related posts about arrays