The documentation for rename() plainly states that if a file with the new name already exists, results are implementation-defined. You are better off deleting any existing 'new name' file first.
The problem with eof() is more insidious. Imagine what would happen to his code if an error flag were set in the middle of that loop. (An infinite loop.)
Always check against good(), and if that fails, you can check to see which flag caused the failure: whether a benign (and wanted) eof() or an obnoxious bad() or fail() of some sort.
Ctrl-D is the EOF character on *nix and in ASCII (EOT).
Ctrl-Z is considered an EOF character on DOS.
However, all this is system dependent and you should not generally see these characters when doing file I/O --as EOF is technically a condition, not a part of a stream.
Hope this helps.
Reputation Points: 1140
Solved Threads: 229
Postaholic
Offline 2,039 posts
since Oct 2007