C++ 十六进制字符串转换为十进制数字:详细指南
可以使用以下方法将十六进制字符串转换为十进制数字:
- 将十六进制字符串转换为整数类型,可以使用
std::stoi函数,例如:
std::string hexStr = '1A';
int decimalNum = std::stoi(hexStr, nullptr, 16);
- 如果需要使用
long long类型,则需要使用std::stoll函数,例如:
std::string hexStr = '1A';
long long decimalNum = std::stoll(hexStr, nullptr, 16);
- 如果需要使用
unsigned long long类型,则需要使用std::stoull函数,例如:
std::string hexStr = '1A';
unsigned long long decimalNum = std::stoull(hexStr, nullptr, 16);
原文地址: http://www.cveoy.top/t/topic/nOg2 著作权归作者所有。请勿转载和采集!