Boost logo

Boost :

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

I previously posted this to the users group
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

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 |
         os << static_cast<int32_t>(x);
         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 § 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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at