这个问题已经在这里有了答案:




已关闭10年。






我正在尝试将十六进制字符串转换为C++中的unsigned int。我的代码如下所示:

string hex("FFFF0000");
UINT decimalValue;
sscanf(hex.c_str(), "%x", &decimalValue);
printf("\nstring=%s, decimalValue=%d",hex.c_str(),decimalValue);

结果为-65536。我通常不会做太多的C++编程,因此将不胜感激。

谢谢,
杰夫

最佳答案

使用%u而不是%d的int输出

关于c++ - C++十六进制字符串到unsigned int ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4801146/

10-12 04:40