+ 2

How To Convert String To Exactly Same Integers In C or C++

eg string 32 -> Integer 32 string 7 -> Integer 7

16th Nov 2017, 3:50 PM
Shubham Pratap Singh
Shubham Pratap Singh - avatar
1 Odpowiedź
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/
9th Jan 2018, 9:42 AM
Abdullah Omar Nasseef
Abdullah Omar Nasseef - avatar