When I read all data from a stream, but make no attempt to read past its end, the stream's EOF is not set. That's how C++ streams work, right? It's the reason this works:
assert(ss.tellg() == 6);
assert(!ss.eof()); // <-- FAILS
assert(ss.tellg() == 6); // <-- FAILS
I think this is a libstdc++ bug (42875, h/t NathanOliver). The requirements on
ignore() in [istream.unformatted] are:
Characters are extracted until any of the following occurs:
n != numeric_limits<streamsize>::max()(18.3.2) and
ncharacters have been extracted so far
— end-of-file occurs on the input sequence (in which case the function calls
setstate(eofbit), which may throw
traits::eq_int_type(traits::to_int_type(c), delim)for the next available input character c (in which case c is extracted).
Remarks: The last condition will never occur if
So we have two conditions (the last is ignored) - we either read
n characters, or at some point we hit end-of-file in which case we set the
eofbit. But, we are able to read
n characters from the stream in this case (there are in fact 6 characters in your stream), so we will not hit end-of-file on the input sequence.
eof() is not set and
tellg() does return 6.