how to print hex number.

Oct 1, 2011 at 7:26pm
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++?
Oct 3, 2011 at 7:12pm
1
2
3
4
#include <iomanip>

int x = 255;
std::cout << std::hex << x;
Oct 3, 2011 at 7:44pm
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.