0

How can i change string number into integer value??

Ex: "5"->5

7th Apr 2020, 3:23 PM
Rahul Jindal
Rahul Jindal - avatar
4 Réponses
+ 2
C++ has a number of conversion functions for this purpose, which you can find in the <string> header. Just follow the link to the documentation and scroll down a bit to the section "Numeric Conversions": https://en.cppreference.com/w/cpp/string/basic_string
7th Apr 2020, 3:26 PM
Shadow
Shadow - avatar
+ 1
No, ASCII codes only exist for single characters.
7th Apr 2020, 3:33 PM
Shadow
Shadow - avatar
+ 1
#include <iostream> #include <sstream> using namespace std; int main() { string no_str = "3"; stringstream ss(no_str); int number; ss >> number; cout << number; return 0; } you can do this one way using stringstream and the other way is using stoi in <string> like Shadow said there are many ways to achieve this.
7th Apr 2020, 8:02 PM
minirkk
minirkk - avatar
0
Do we have ascii code for more than 1 digit number?? Ex. 10 or 111
7th Apr 2020, 3:28 PM
Rahul Jindal
Rahul Jindal - avatar