getline discarding eof

Reading lines from file using an eofbit-controlled while loop. Last line does not have an eol (newline) character, so getline uses the eof in its place. Fine. Now there is no eof to stop the next read attempt.

I can treat the symptom with an empty string if test. Don't know how to treat the cause.

Any suggestions?
1
2
3
4
while (std::getline(file, line))
{
   // do something with line.
}
Thank you, no more out_of_range error and outputs the way I want it.
Topic archived. No new replies allowed.