String to Int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

String to Int

Is there any function in c++ work like "val" in pascal ? I need to convert a string into an integer. Not a whole number just one by one start from the last character Ex: 12345 start from 5 to 1

21st Oct 2017, 1:46 PM
thong nguyen
thong nguyen - avatar
2 Answers
+ 5
Here you can read about the function: http://www.cplusplus.com/reference/string/stoi/
21st Oct 2017, 2:10 PM
Shadow
Shadow - avatar
0
Thank you. But i tried the atoi function. I have a string "12345" i want to print each number from the end to the start, but if i do something like int number=atoi(&string[3]); output: 45 How i can print one by one number ?
22nd Oct 2017, 2:07 AM
thong nguyen
thong nguyen - avatar