libstdc++/3720: Problems with num_get

Philip Martin philip@codematters.co.uk
Fri Dec 7 17:37:00 GMT 2001


Benjamin Kosnik <bkoz@redhat.com> writes:

> > 3. Trying the code, input of std::numeric_limits<T>::max() in octal or
> >    hex doesn't appear to work for integers, e.g. reading 017777777777
> >    into a long on x86 doesn't work, it appears to accept one character
> >    too few. Decimal works.
> 
> Hmm. I'll look at this, thanks.

I was assuming that

   std::istringstream i( "017777777777" );
   long x = 0;
   i >> x;

would deduce octal from the leading zero, as that's what stdio "%i"
does. Investigation shows that it is reading decimal, which is then
one digit too long. Using an explicit manipulator

   i >> std::setbase(0) >> x;
or
   i >> std::oct >> x;

causes the number to be read correctly. I suppose it's table 89 in
27.4.4.1 that determines that dec is the default?  I didn't expect
that.

Philip




More information about the Gcc-bugs mailing list