views:

115

answers:

2

Hi, I understand that you can use iomanip to set a precision flags for floats (e.g. have 2.0000 as opposed to 2.00).

Is there a way possible to do this, for integers?

I would like a hex number to display as 000e8a00 rather than just e8a00 or 00000000 rather than 0.

Is this possible in C++, using the standard libraries?

+9  A: 

With manipulators:

std::cout << std::setfill('0') << std::setw(8) << std::hex << 0 << std::endl;

Without manipulators:

std::cout.fill('0');
std::cout.width(8);
std::cout.setf(std::ios::hex, std::ios::basefield);
std::cout << 42 << std::endl;
Nick Meyer
Yes, this works, thanks.
Anthony
+3  A: 
swestrup