C++ cout hex values?


Question

I want to do:

int a = 255; 
cout << a;

and have it show FF in the output, how would I do this?

1
132
2/1/2019 7:17:24 AM

Use:

#include <iostream>

...

std::cout << std::hex << a;

There are many other options to control the exact formatting of the output number, such as leading zeros and upper/lower case.

183
1/8/2017 6:36:50 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon