This is the mail archive of the
mailing list for the libstdc++ project.
Re: How do I select a version of libstdc+ to link against?
On 22 September 2011 12:30, David Aldrich wrote:
>> And if you want to detect a failure to read a boolean (rather than simply EOF)
>> follow the loop with:
>> ? ? ? ?if (!iss.eof())
>> ? ? ? ? ? ?cout << "fail" << endl;
>> That should give the same behaviour with 4.1 and 4.4 for your test, and for
>> the case where the stream fails because it contains a non-boolean value such
>> as "true true x" or "true true fal"
>> Testing !iss.eof() tells you that the loop exited for some reason other than
>> reaching EOF, i.e. it couldn't convert the input to bool.
> I'm sorry, but that is just giving the same problem as before. ?In the case that the input stream contains valid Booleans, after the last Boolean is read, eof() is not true. ?My understanding of the bug report that I referred to earlier, is that one must attempt to read past the end of the stream for eof() to return true, which won't happen in the normal case.
If the stream only contains valid booleans, the loop will terminate
after reaching EOF and trying to extract another boolean, which will
set both eofbit and failbit.
The !iss.eof() test isn't quite right though, it will print "fail" for
"true true x" but it will cause an incomplete value at the end of the
stream to be silently discarded. So I was wrong to say it will print
"fail" for "true true fal", that will silently ignore the partial
But while(iss>>boolalpha>>b) does give more consistent behaviour
between 4.1 and 4.4