PROBLEM OF CONVERTING STRING TO INTEGER | SoloLearn: Learn to code for FREE!

+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

2/15/2020 4:26:36 PM

Rytis Karalius

6 Answers

New Answer

+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())

+2

The value you given is not in range of intiger. Because of overflow, you are getting converted value..

+2

Yes. Use stol(code) ; I just seen now..

+2

If you are using a long long to store the result then use stoll() not stol(). See http://www.cplusplus.com/reference/string/stoll/ either that or use a long to store the value returned from stol().

+1

Théophile Thanks for help :)

0

Jayakrishna maybe you know how to solve the problem?