the file ifstream is reading from is a .dat file, in this format:
first 1
second 2
third 3
fourth 4
This is the exact file ifstream is opening, but for some reason when I check my output file is shows like it should except it displays "fourth 4" twice,
e.g :
fourth 4
fourth 4
Why is my loop iterating more than it should?
Don't know if it helps, but my count has been initialized as 0 and equals 5 at the end of the loop.
In short, to trigger eof() to return true, you need to read beyond the last character of the file. The last good read reads up to (and including) the last character, and no more; eof() is not triggered, and the loop runs one more time (hitting eof right away). In this last run nothing gets read, and your variables retain their values from the previous pass.