我正在寻找一种可移植的方法来 a) 将字符串转换为 64 位有符号整数 (int64_t),以及 b) 确定它是否不适合(溢出)。有什么办法可以做到这一点吗?
最佳答案
strtoll
已经非常便携了。如果不是您的情况,您可以随时复制 GNU C 运行时库并将其添加到您的项目中...
errno = 0;
long long val = strtoll (string, NULL, 0);
if (errno == ERANGE)
// there was an overflow conversion error
关于c++ - 确定数字(编码为字符串)是否适合 C++ 中的 64 位整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9900089/