Boost logo

Boost Users :

From: Phil Endecott (spam_from_boost_users_at_[hidden])
Date: 2006-12-18 12:13:26


Dear All,

This does what I want:

   uint8_t i = 65;
   printf("i = %d\n",i);

It prints "65". This doesn't:

   uint8_t i = 65;
   cout << "i = " << i << "\n";

It treats i as a char, since uint8_t is a typedef for char deep in some
header file somewhere, and prints "A".

I was hoping that boost::format would do what I wanted:

   uint8_t i = 65;
   cout << boost::format("i = %d\n") % i;

But it seems to have the same, unwanted, behaviour as cout<<i.

Is there anything that I can do to my code to get the effect that I
want? If not, is there anything that can be changed in boost::format
to make it do what I want? At the moment I have to write things like

cout << "i = " << static_cast<unsigned int>(i) << "\n";

which is a lot of typing and obfuscates what is actually going on.

Any suggestions would be much appreciated.

Cheers,

Phil.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net