This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]