libstdc++
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Fri Feb 11 00:32:00 GMT 2000
> There is a problem with the sync or clear function of the iostream
> class. The attached example program works fine with other compilers
> (Mickeysoft Visual C++) but doesn't with gcc.
Thanks for your bug report. I think this is not a bug in g++, but in
your code. If VC++ behaves as you intended, it would also indicate a
bug in VC++.
To read an integer from a stream, character by character is extracted
and accumulated, to see whether it is part of a number
(22.2.2.1.2/9). The input pointer is only advanced if the character is
accumulated (22.2.2.1.2/10). So the first character that is not part
of the number will still be in the input stream when (cin>>a) returns.
As a result, it will be re-read the next time input is performed. This
will give you another error, and so on.
If you doubt this explanation, please ask for clarification in one of
the C++ fora, such as comp.lang.c++.moderated.
Regards,
Martin
More information about the Gcc-bugs
mailing list