我有以下字符串:
sThis = "2154910440";
unsigned int iStart=atoi(sThis.c_str());
然而,结果是
iStart = 2147483647
有人看到我的错误了吗?
发布于 2018-07-11 21:54:04
下面的代码将使用C++11对其进行转换:
std::string sThis = "2154910440";
unsigned int iStart = static_cast<unsigned int>(std::stoul(sThis));
std::stoul
将返回一个比unsigned int
大的unsigned long
。
static_cast
会将其转换为正确的类型。
https://stackoverflow.com/questions/18037835
复制相似问题