Problem with loading a file
I currently have this code for loading the contents of a file in a function,
Code:
void loadfile1()
{
string line;
cout << "File 1 - \n \n";
ifstream infile("test.txt", ios::in);
while( !infile.eof() )
{
getline (infile,line);
cout << line << endl;
}
infile.close( );
}
This code works fine when there is data in the file, but when there isn't it goes into an infinite loop.
I have tried a few things to fix it, but I think I just made it worse. Any ideas?
Thanks in advance.