c++ 将一个16进制字符串数组转换成十六进制无符号int
可以使用标准库中的函数 std::strtoul 将字符串转换成无符号整数。
示例代码:
#include <iostream>
#include <cstdlib>
int main()
{
const char* hex_str = "0x1A2B3C4D";
unsigned int hex_int = std::strtoul(hex_str, nullptr, 16);
std::cout << "Hex string: " << hex_str << std::endl;
std::cout << "Hex integer: " << hex_int << std::endl;
return 0;
}
输出:
Hex string: 0x1A2B3C4D
Hex integer: 439041101
原文地址: https://www.cveoy.top/t/topic/eEHR 著作权归作者所有。请勿转载和采集!