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 number in c++
// For C++11 and later versions
string str1 = "45";
string str2 = "3.14159";
string str3 = "31337 geek";
int myint1 = stoi(str1);
int myint2 = stoi(str2);
int myint3 = stoi(str3);
// Output
stoi("45") is 45
stoi("3.14159") is 3
stoi("31337 geek") is 31337
string to int c++
#include <sstream>
using namespace std;
int main()
{
stringstream string_to_int;
string s1="12345";
int n1;
string_to_int<<s1;
//也可以使用string_to_int.str(s1);
//或者 s1=string_to_int.str();
string_to_int>>n1;
cout<<"s1="<<s1<<endl;//s1=12345
cout<<"n1="<<n1<<endl;//n1=12345
}
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