Answers for "c++ parse int"

C++
3

c++ parse int

std::string s = "10";
int i = std::stoi(s);
Posted by: Guest on July-01-2020
3

string to int in c++

#include <iostream>
#include <string>
using namespace std;
int main() {
 
    string s = "10";
 
    try
    {
        int i = stoi(s);
        cout << i << '\n';
    }
    catch (invalid_argument const &e)
    {
        cout << "Bad input: std::invalid_argument thrown" << '\n';
    }
    catch (out_of_range const &e)
    {
        cout << "Integer overflow: std::out_of_range thrown" << '\n';
    }
 
    return 0;
}
Posted by: Guest on December-10-2020
8

c++ string to int

atoi( str.c_str() )
Posted by: Guest on May-13-2020

Browse Popular Code Answers by Language