PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
The problem is with line 86 while (!fo.eof()). This does not work the way that you are thinking. As you can see here by the time the while condition gets the message that "eof" has been reached you have processed the last read twice. Most of the time the read is done in the while condition.
To use what you have now. Try doing the first read before the while loop and inside the while loop put the read at the bottom of the loop and "!eof" should work better.
Beyond that I would have to test the program to see how it is working.
To use what you have now. Try doing the first read before the while loop and inside the while loop put the read at the bottom of the loop and "!eof" should work better.
Rearranging the position of the read statements is a valid suggestion. But it is still better to simply test the file status, for example while( fo ) where fo is the name of the file stream.
One reason for that is there may be other problems with reading the file which means eof() does not get set at all (if a different error occurs first). Hence safer and less to unlearn to simply avoid using eof in these circumstances.