how to print hex number.

how to print hex numbers in c++.

i can easily do this in C like this....
1
2
int x=255;
printf("%X",x);

and this will output FF.

how to do this in C++?
1
2
3
4
#include <iomanip>

int x = 255;
std::cout << std::hex << x;
hi,
it is even easier:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <iomanip>
using namespace std;

int main(){
	int x=255;
	cout<<"x: "<<x<<"\n x(hex):"<<hex<<x<<endl;
	system("pause");//to see the outcome
	}
Topic archived. No new replies allowed.