Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

string to int in c++

#include <iostream>
#include <string>
using namespace std;
int main() {
 
    string s = "10";
 
    try
    {
        int i = stoi(s);
        cout << i << '
';
    }
    catch (invalid_argument const &e)
    {
        cout << "Bad input: std::invalid_argument thrown" << '
';
    }
    catch (out_of_range const &e)
    {
        cout << "Integer overflow: std::out_of_range thrown" << '
';
    }
 
    return 0;
}
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #string #int
ADD COMMENT
Topic
Name
5+7 =