Boost logo

Boost Users :

From: Brian Crowder (crowder_at_[hidden])
Date: 2006-12-18 12:30:12


You can just cast the value to an int (in both the boost::format
example, and in the iostreams example) to get what you want. (the
varargs usage you demonstrate with printf is essentially a much more
dangerous form of casting anyway).

-- Brian

On Dec 18, 2006, at 10:13 AM, Phil Endecott wrote:

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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