Converting hex to dec C++

旧街凉风 提交于 2019-12-04 07:08:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!