← Back to Question List
C++ Quiz #137
What stoi Throws
std::stoi is called with a normal number, with text, and with a number far too large for an int. What is printed?
📄 Code
1#include <iostream>2#include <stdexcept>3#include <string>45void parse(const std::string& text) {6 try {7 int value = std::stoi(text);8 std::cout << "number " << value << "\n";9 } catch (const std::invalid_argument&) {10 std::cout << "not a number: " << text << "\n";11 } catch (const std::out_of_range&) {12 std::cout << "too big: " << text << "\n";13 }14}1516int main() {17 parse("42");18 parse("abc");19 parse("999999999999999999999");20 return 0;21}