Converting string to integer (C++) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Converting string to integer (C++)

I have one homework related to convert string to integer. Can anybody give me some example?

29th Oct 2019, 9:24 AM
Aaron Pong
Aaron Pong - avatar
4 Answers
+ 1
Make a program that reads every character of the string and then adds every read character in a certain way
29th Oct 2019, 9:45 AM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 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
29th Oct 2019, 1:50 PM
Rohit
+ 1
C++ has inbuilt function for converting string into integer ( stoi function) http://www.cplusplus.com/reference/string/stoi/
29th Oct 2019, 10:57 AM
Vijay Meena
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
29th Oct 2019, 2:58 PM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar