This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
- From: paolo at gcc dot gnu dot org
- To: doerntge at kiwilogic dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: 18 Jan 2002 21:51:00 -0000
- Subject: Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
- Reply-to: paolo at gcc dot gnu dot org, doerntge at kiwilogic dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: std::ifstream::operator>>(int&) fails with negative hex numbers
State-Changed-From-To: feedback->analyzed
State-Changed-By: paolo
State-Changed-When: Fri Jan 18 13:51:00 2002
State-Changed-Why:
The testcase:
#include <fstream>
#include <iostream>
bool stream_in( void )
{
std::ifstream is( "foo.txt" );
is.setf( std::ios::hex, std::ios::basefield );
int i=0;
if ( !(is.good() && is.is_open()) )
return false;
is >> i;
if ( !is )
return false;
if ( is.peek() == '\n' )
is.ignore();
if ( !is )
return false;
is >> i;
if ( !is )
return false;
if ( is.peek() == '\n' )
is.ignore();
if ( !is )
return false;
return true;
}
bool stream_out( void )
{
std::ofstream os( "foo.txt" );
os.setf( std::ios::hex, std::ios::basefield );
if ( !(os.good() && os.is_open()) )
return false;
os << -42 << '\n' << 42 << '\n';
return true;
}
int main( int argc, char*argv[] )
{
if ( !stream_out() )
std::cerr << "std::ostream failed" << std::endl;
else if ( !stream_in() )
std::cerr << "std::istream failed" << std::endl;
return 0;
}
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5424