我给出了一个字符串y,我保证它只包含数字。在使用stoi函数将其存储在int变量中之前,如何检查它是否超出整数的范围?在C++中检查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?
为什么不捕捉异常并相应地处理它? – PlasmaHH
您可能需要阅读有关解析字符串时出现问题的参考资料[如此](http://en.cppreference.com/w/cpp/string/basic_string/stol)。 –
非常感谢你们!是的,我会通过参考! –