bug in istringstream::str(string)
Benjamin Kosnik
bkoz@cygnus.com
Sat Apr 1 00:00:00 GMT 2000
> I don't have the final version of the ANSI C++ Standard. Can you tell me if
> it is mandatory to call clear before setting a new source-string or is it a
> workaround for a bug in libstdc++?
To be standards-conformant, you must call istream::clear(). This is
not a bug. The istringstream instance in your example is in an error
state, and thus istream::sentry will not allow extraction.
Here's an annotated example, based on your email:
// void str(const basic_string&)
is01.str(str01);
state1 = is01.rdstate();
is01 >> a;
state2 = is01.rdstate();
test &= a = i01;
// 22.2.2.1.2 num_get virtual functions
// p 13
// in any case, if stage 2 processing was terminated by the test for
// in == end then err != ios_base::eofbit is performed.
test &= state1 != state2;
test &= state2 == stateeof;
is01.str(str01);
is01 >> b;
test &= b != a;
// as is01.good() is false, istream::sentry blocks extraction.
is01.clear();
state1 = is01.rdstate();
is01 >> b;
state2 = is01.rdstate();
test &= b == a;
test &= state1 != state2;
test &= state2 == stateeof;
Hope this helps.
-Benjamin
More information about the Libstdc++
mailing list