0
How to convert string to integer in c++
string number_str = "1"; and i want to convert the number_str to integer
3 Réponses
+ 4
You may use this Function, convert:
#include <sstream>
int convert(string d)
{
int var;
stringstream ss(d);
ss>>var;
return var;
}
int main()
{
cout<<convert("1");
}
Also, there are standard string conversion functions stoi, stol, stof etc for conversion of string to int, long and float respectively. You may use those if you don't wish to define your own function.
+ 4
https://code.sololearn.com/c2T2H41LEKS9/?ref=app
You have simply example code.