Posted on

Description

Submission

  • stoi function throws errors but the int() constructor does not
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;


int main(){
    string S;
    cin >> S;
    try {
        cout << stoi(S);
    } catch(exception &e) {
        cout << "Bad String";
    }
    return 0;
}

Reference

  1. Day 16: Exceptions – String to Integer
  2. http://www.cplusplus.com/reference/string/stoi/

Leave a Reply

Your email address will not be published. Required fields are marked *