问题
Convert to hex:
cout << hex << int(x) << endl;
How to convert conversely, from hex to dec?
Enter hex number simple:
cin >> hex >> x;
回答1:
You can use the std::dec IO manipulator:
std::cout << std::dec << int(x) << endl;
Note that this is only necessary if you have previously used std::hex or other means to manipulate the base of std::cout. Otherwise you need take no action: the default for an int is decimal.
回答2:
Don't use the std::hex manipulator?
std::cout << int(x) << std::endl;
来源:https://stackoverflow.com/questions/17781115/converting-hex-to-dec-c