+ 2
How To Convert String To Exactly Same Integers In C or C++
eg string 32 -> Integer 32 string 7 -> Integer 7
2 Réponses
0
Use stoi() function from <string> library.
Syntax:
stoi(str,idx,base);
Example (In you context):
#include <iostream>
#include <string>
using namespace std;
int main(){
string number;
cin>>number;
int toInt = stoi(number, nullptr , 10);
cout<<toInt;
return 0;
}
However, it does not work in sololearn's Code Playground, but I can affirm you that it will work anywhere else.
For better description:
http://www.cplusplus.com/reference/string/stoi/