C++: ifstream::getline problem
- by Jay
I am reading a file like this:
char string[256];
std::ifstream file( "file.txt" ); // open the level file.
if ( ! file ) // check if the file loaded fine.
{
// error
}
while ( file.getline( string, 256, ' ' ) )
{
// handle input
}
Just for testing purposes, my file is just one line, with a space at the end:
12345
My code first reads the 12345 successfully. But then instead of the loop ending, it reads another string, which seems to be a return/newline.
I have saved my file both in gedit and in nano. And I have also outputted it with the Linux cat command, and there is no return on the end. So the file should be fine.
Why is my code reading a return/newline?
Thanks.