我給出了一個字符串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)。 –
非常感謝你們!是的,我會通過參考! –