string to int c++
int number = std::stoi(string, base); // str to int
int number = std::stoi("100",10); // number = 100
long int number = std::strtol(string, endptr, base); // str to long int
string to int c++
int number = std::stoi(string, base); // str to int
int number = std::stoi("100",10); // number = 100
long int number = std::strtol(string, endptr, base); // str to long int
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us