【发布时间】:2013-09-03 05:59:51
【问题描述】:
我得到了一个字符串 y,我确保它只包含数字。在使用 stoi 函数将整数存储到 int 变量之前,如何检查它是否超出整数的范围?
string y = "2323298347293874928374927392374924"
int x = stoi(y); // The program gets aborted when I execute this as it exceeds the bounds
// of int. How do I check the bounds before I store it?
【问题讨论】:
-
为什么不捕获异常并相应地处理呢?
-
您可能想阅读参考such as this,了解当解析字符串出现问题时会发生什么。
-
非常感谢大家!是的,我将通过参考!