seekg(x) does not alter fstream::eofbit
Weldon, Kenneth A
kenneth.a.weldon@lmco.com
Tue May 23 08:12:00 GMT 2000
Given an input file, 'test.txt', made up of integers, the
following code should read the list twice:
#include <fstream>
int main(void)
{
ifstream InFile("test.txt");
int i;
while(!(InFile.eof()))
InFile >> int;
InFile.seekg(0); // Should place file pointer at beginning of file and,
if not past eof, reset eofbit
while(!(InFile.eof()))
InFile >> int; // This line is never reached because eofbit never
reset
}
Since the eofbit was never reset, the condition on the second while loop is
not passed,
and the second attempt at reading the file fails.
I believe that the seekg() function should not only place the file pointer
at a certain
spot in the file, but that it should also check the status bits and change
them if
necessary (especially the eofbit).
Thank you,
Andy Weldon
Lockheed Martin Missiles and Space / BMC3I
kenneth.a.weldon@lmco.com < mailto:kenneth.a.weldon@lmco.com >
256.722.4149
This e-mail may contain Lockheed Martin private and privileged material for
the sole use of the intended recipient. Any review or distribution by others
is strictly prohibited. If you are not the intended recipient, please
contact the sender and delete all copies.
More information about the Gcc-bugs
mailing list