According to GCC 4.6.2 istream.tcc
:
basic_istream<_CharT, _Traits>::
seekg(off_type __off, ios_base::seekdir __dir)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
// Clear eofbit per N3168.
this->clear(this->rdstate() & ~ios_base::eofbit);
I hit this accidentally -- and could not figure out why I was getting an infinite while (!eof)
loop. Basically, when seekg is invoked with a ZERO length -- you still get the eof reset. Is there a reason for resetting the eof bit even for a zero length std::ios_base_::cur
search? This does NOT happen in VC10/11.
And what is N3168?
The problem is that you are abusing eof()
: the only use for this flag is to determine if you last read failed because you hit the end of the file (well, it doesn't even do that to be fair: even if eof()
is set that may not be the real cause although it probably was). To determine the stream state use the conversion to bool
:
while (in) ...
Note that you still need to check after reading if the read was successful.
N3168 is a paper discussed by the standardization committee. Off-hand I don't know what particular topic it discusses beyond that it was in response to a national body defect report.