Formatting in C++

John Wildberger wildberger-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org
Fri Dec 26 02:21:36 UTC 2003


On December 25, 2003 08:51 pm, Jing Su wrote:
> > How can I use cout <<... to perform the equivalent to
> > printf( " %.2X ",buf[i] );
> > when buf[]  was declared as   uint8_t  buf[] ;
> > and the content of buf[i] are hex numbers like 0x5e, or 0xfd, etc ?
> > I think that I would have to include #include <iomanip> ,but I am at a
> > loss how to accomplish the formatting.
> > John
>
> #include<iomanip>
>
> cout.setf(std::ios::fixed | std::ios::hex);
> cout << std::setprecision(2) << buf[i];
I tried this before; it compiles without any complaint, but gives garbage 
output.
I tried Google, but no relevent info.
John
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list