That's one of the most trick thing of the C++ library, because of certain names, suggesting things that are not what they effectively are.
The
eof
function, according to
the reference[
^]
"returns true if the eofbit stream's error flag has been set by a previous i/o operation. This flag is set by all standard input operations when the End Of File is reached in the sequence associated with the stream"
The "End OF File", here, is not the "physical end", but a particular ASCII character (Ctrl+Z) that is supposed "to boldly be where all characters are before" (yes: Captain Kirk participate in the ASCII specs). But, since when the teletype world has been "superseeded" by computers, Ctrl+Z is just a byte like any other: it may have character after, and it may be even not present.
Instead of check for EOF, you shold check for "bad()", that returns the state of a bit that sets up when reading become impossible (either because there is nothing more to read or because what is read is not useful to fill re variable it is directed to).
This char is done by istream::operator void*(), by returning NULL if the stream is "bad". So that
stream
can be an exit condition for a loop.
In your case
while(finsort)
{ .... }
Should behave as expected.