libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
paolo@gcc.gnu.org
paolo@gcc.gnu.org
Fri Jan 18 13:51:00 GMT 2002
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
More information about the Gcc-prs
mailing list