The overflow exception while using stoi() function in cpp. Please explain the case for the example I am adding:
string s = “112233445566”;
int i = stoi(s,0,10);
The exception occurs for the integer ‘i’ upon conversion using stoi() however, not for the string ‘s’. The out_of_range error is being issued for only ‘i’ and not for ‘s’. Why? Please elaborate upon this.
int maximum value is 2147483647 (most of the time, it can depends of the compiler/system).
You are trying to put 112233445566 into an int. It is not possible, so stoi throws a out_of_range exception.