Boost logo

Boost Users :

From: Philipp Henkel (threadpool_at_[hidden])
Date: 2006-11-03 10:27:44


Hi Freddie,

I reported this strange behaviour on the boost.devel list some time ago.
Unfortunately, I did not get an answer.
Several people I know ran into this trap and it would be very helpful if a
char is converted to int in case of %d formatter.

A cast to int should help:
std::cout << (fmt % (int)port) << std::endl;

Best regards,
Philipp

On 11/3/06, Wu Yinghui, Freddie <yhwu_at_[hidden]> wrote:
>
> Hi all,
>
> I'm using Boost CVS version in the release branch. But according to the
> change log, it seems that this problem shall exist in Boost 1.33 too.
>
> I have the following code snippet, which doesn't produce the desired
> output:
>
> typedef unsigned char qquint8;
> qquint8 port = 1;
> boost::format fmt("Trying to probe COM%1$d:...");
> std::cout << (fmt % port) << std::endl;
>
> The output will was:
> Trying to probe COM^A:...
> but what I want should be:
> Trying to probe COM1:...
>
> I understand that the underlying stream might have treated port as a
> character, thus output it as a character. But from Boost.Format's
> documentation, this doesn't seem obvious to me, since it always refers
> this as "printf-like" format string.
>
> So my question is: Is this considered a bug (thus, shall be fixed), or
> is it just considered a special case (thus, shall be explicitly
> documented under the "Differences of behaviour vs printf" section)?
>
> Cheers,
>
> Freddie
>
> --
> Wu Yinghui, Freddie
> Research & Development
> Senior Software Engineer
>
> Volume Interactions Pte Ltd
> 1 Kim Seng Promenade, #12-01
> Great World City East Tower
> Singapore 237994
> Tel: +65 62226962 (Ext 216)
> Fax: +65 62226215
> Email: yhwu_at_[hidden]
> URL: http://www.volumeinteractions.com
>
> Important: This message is intended for the recipient(s) addressed
> above. It contains privileged and confidential information. If you are
> not the intended recipient, please notify the sender immediately by
> replying to this message and then delete it from your system. You must
> not read, copy, use, or disseminate this communication in any form.
> Thank you.
>
>
> _______________________________________________
> 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