Formatting in C++ (fwd)

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


On December 26, 2003 10:12 am, Jing Su wrote:
> My appologies... I double checked and realized I copied the code
> incorrectly.  Heh. Should've used cut&paste instead of re-typing it.
>
> The line should read:
>
> std::cout << setw(2) << std::hex << (unsigned it)buf[i];

This did do the trick.With  "using namespace std;" and the addition of 
"<< setfill('0')"  I got very close to the result of printf( "%.2X  ",buf[i]);
This is my code snippet:
   for (i=0; i<max; i++)
     cout <<setfill('0')<<setw(2)<< hex <<(unsigned int)buf[i]<<" ";
===>
01 00 00 00 5a ff 00 f0 c3 e2 

Note the capital X in the printf. Is there something similar for cout<< ,  
that would give hex in capitals?

Thanks for your trouble in helping me along. I am sure that other people on 
the list , who are interested in C++ will also appreciate your effort.

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