From: Luke Elliott (luke_elliott_at_[hidden])
Date: 2006-05-31 14:54:29


I previously posted this to the users group
(http://search.gmane.org/search.php?group=gmane.comp.lib.boost.user&query=%5Bformat%5D+%25d%2C+%25u+etc.+with+%28unsigned%29+char+types)
with no response - I thought I'd try here before giving up, so sorry for
repeating myself...

Anyway, using %d, %u etc. with char types prints the character rather
than the integral value.

I've had a quick hack around with the code, adding the following to
feed_args.hpp:

template< class Ch, class Tr> inline
void put_last( BOOST_IO_STD basic_ostream<Ch, Tr> & os, const char& x ) {
     if (os.flags() & (std::ios_base::dec | std::ios_base::hex |
std::ios_base::oct))
         os << static_cast<int32_t>(x);
     else
         os << x ;
}

(ditto for unsigned char)

and modding internals.hpp:

template<class Ch, class Tr> inline
void stream_format_state<Ch,Tr>:: reset(Ch fill) {
     // set our params to standard's default state. cf § 27.4.4.1 of
the C++ norm
     width_=0; precision_=6;
     fill_=fill; // default is widen(' '), but we cant compute it
without the locale
     flags_ = std::ios_base::skipws;
     // the adjust_field part is left equal to 0, which means right.
     exceptions_ = std::ios_base::goodbit;
     rdstate_ = std::ios_base::goodbit;
}

(i.e. remove std::ios_base::dec from flags_) 'works' (vc71) for the very
few limited cases I've tried. I'm sure that's horribly broken for any
number of reasons, but I'm more interested in whether this is considered
a problem or not? It seems a shame to have to cast arguments to format
if they happen to be char and %d is specified in the format string (also
obviously making writing generic code more difficult!).

Thanks in advance

Luke Elliott.