0
Converting string to integer (C++)
I have one homework related to convert string to integer. Can anybody give me some example?
7 Réponses
+ 1
Make a program that reads every character of the string and then adds every read character in a certain way
+ 3
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "123";
//stoi is string to integer
int d = stoi(str);
cout << d * 2;
return 0;
}
OUTPUT:
246
+ 1
C++ has inbuilt function for converting string into integer ( stoi function)
http://www.cplusplus.com/reference/string/stoi/
0
~ swim ~ That's so cool, I knew that trick worked for transforming to upper or lower case, I didn't know you could also use it for numbers