• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ people... a little help with display please

Jumpem

Lifer
I want to output an 8 digit hex value, say 00000104. When I use cout it gets rid of leading 0's and prints "104". How can I have output that shows leading 0's as well?
 
cout << setiosflags(ios_base::right) << setw(8) << setfill('0') << yourthing;

oh yeah remember to include <iomanip>
 
Originally posted by: dighn
cout << setiosflags(ios_base::right) << setw(8) << setfill('0') << yourthing;

oh yeah remember to include <iomanip>


Ok, what if I have other hex and string values being output after that. Can I put them in the same cout statement or do I need another one? I guess, what is the scope of setiosflags, setw, and setfill?
 
Originally posted by: Jumpem
Originally posted by: dighn
cout << setiosflags(ios_base::right) << setw(8) << setfill('0') << yourthing;

oh yeah remember to include <iomanip>


Ok, what if I have other hex and string values being output after that. Can I put them in the same cout statement or do I need another one? I guess, what is the scope of setiosflags, setw, and setfill?

i'm not totally sure without experimenting with it. i think it persists for at least the whole statement.
 
if you do it this way...
cout << setiosflags(ios_base::right) << setw(8) << setfill('0') << yourthing;
its set just for that line.



if you do it this way...
cout.setiosflags(ios_base::right);
its set permanently until you unset it.
 
Back
Top