You are viewing a single comment's thread. Return to all comments →
I did not know this is so simple
int main() { string S;
getline(cin, S); try { int integerValue = stoi(S); // Convert string to integer cout << integerValue << endl; // Print the integer value } catch (const invalid_argument&) { cout << "Bad String" << endl; // Handle conversion error } catch (const out_of_range&) { cout << "Bad String" << endl; // Handle range error } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Day 16: Exceptions - String to Integer
You are viewing a single comment's thread. Return to all comments →
I did not know this is so simple
int main() { string S;
}