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