I'm looking for a way to convert hex
(hexadecimal) to dec
(decimal) easily. I found an easy way to do this like :
int k = 0x265;
cout << k << endl;
但我无法输入265
。无论如何,它是否可以像这样工作:
Input: 265
输出:613
有办法做到这一点吗?
Note:我试过了:
int k = 0x, b;
cin >> b;
cout << k + b << endl;
但它不起作用。
#include <iostream>
#include <iomanip>
#include <sstream>
int main()
{
int x, y;
std::stringstream stream;
std::cin >> x;
stream << x;
stream >> std::hex >> y;
std::cout << y;
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)