+ 1

PROBLEM OF CONVERTING STRING TO INTEGER

I could be wrong, but shouldn't it print the same result as it is in string? What is the problem and how should I solve It? https://code.sololearn.com/cU6jE8t644ip/?ref=app

15th Feb 2020, 4:26 PM
Rytis Karalius
Rytis Karalius - avatar
6 Antworten
+ 2
Try using function stol. It converts a string to a long integer. std::cout << std::stol(code) ; Edit : you can do, if you want : std::cout << atol(code.c_str())
15th Feb 2020, 5:14 PM
Théophile
Théophile - avatar
+ 2
The value you given is not in range of intiger. Because of overflow, you are getting converted value..
15th Feb 2020, 4:39 PM
Jayakrishna 🇮🇳
+ 2
Yes. Use stol(code) ; I just seen now..
15th Feb 2020, 5:17 PM
Jayakrishna 🇮🇳
+ 1
Théophile Thanks for help :)
15th Feb 2020, 5:16 PM
Rytis Karalius
Rytis Karalius - avatar
0
Jayakrishna maybe you know how to solve the problem?
15th Feb 2020, 4:44 PM
Rytis Karalius
Rytis Karalius - avatar