【发布时间】:2018-04-14 00:28:21
【问题描述】:
我正在用 C++ 编写,我有一个字符串。我想检查这个字符串是否只是数字,如果是我想将类型更改为 long int。
stringT = "12836564128606764591";
bool temp = false;
for(char& ch : stringT)
{
if(!isdigit(ch))
{
temp=true;
break;
}
}
if(temp != true)
{
itm = new Item_int((long long) strtoll(stringT.c_str(), NULL, 0));
std::cout << " itm:" << *itm << std::endl;
}
但是打印的结果是:9223372036854775807
【问题讨论】:
-
Item_int到底是什么? -
请阅读minimal reproducible example。鉴于您在此处显示的代码,没有人能够确切地告诉您为什么会得到该输出。如果不相关,您可以从示例中删除
Item_int
标签: c++ string types long-integer strtol