我正在将字符串从十六进制转换为十进制。问题是在 Visual Studio 编译器中,转换返回了错误的值。但是,当我在终端使用 g++ 编译器在 Mac 中编译相同的代码时,会正确返回值。
为什么会这样?
#include <string>
#include <iostream>
using namespace std;
int main()
{
string hex = "412ce69800";
unsigned long n = strtoul( hex.c_str(), nullptr, 16 );
cout<<"The value to convert is: "<<hex<<" hex\n\n";
cout<<"The converted value is: "<<n<<" dec\n\n";
cout<<"The converted value should be: "<<"279926183936 dec\n\n";
return 0;
}
输出: