This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Misreading bool from istringstream
- From: Benoît Sibaud <benoit dot sibaud at rd dot francetelecom dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 12 Mar 2002 16:25:15 +0100
- Subject: Misreading bool from istringstream
- Organization: France Telecom R&D
Hi,
I was testing my own input/output library and found something strange
with bool and istringstream.
8<--------------------------------
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
bool b;
string t = "-1";
istringstream iss(t);
iss >> b;
cout << b << "#" << iss.good() << iss.fail() << iss.eof() << iss.bad()
<< endl;
}
8<--------------------------------
i686-pc-linux-gnu g++ 3.0.4: 1#0010
i686-pc-linux-gnu g++ 2.95.4: 1#1000
sparc-sun-solaris2.7 CC 5.0: 0#0110
sparc-sun-solaris2.7 g++ 3.0.4: 1#0010
mswin-32 VC++ 6.0: 1#0110
Tested on different values with g++ 3.0.4:
-3#1#0010
-2#1#0010
-1#1#0010
0#0#0010
1#1#0010
2#0#0110
3#0#0110
11#0#0110
02#0#0110
01#1#0010
Did I miss something or is it a bug?
(i.e. currently x < 0 is true, x == 0 is false, x == 1 is true, x > 1 is
false)
--
Benoît Sibaud
R&D Engineer France Telecom