vendredi 20 février 2015

c++ stol throwing out of range exception for string length 10 or longer

I am currently trying to convert a string of length 18 which represents a long integer into a long integer so that I can then do a multiplication with the string. When I use stol to try to do the conversion, it runs into an out of range memory exception anytime the string length exceeds 10. It works fine when the string length is less than 10. Below is the relevant parts of my code:



for (unsigned int i = 0; i < numbers.size(); i++)
numbers[i] = numbers[i].substr(0, 10);

for (unsigned int i = 0; i < numbers.size(); i++)
n = stol(numbers[i].c_str());

Aucun commentaire:

Enregistrer un commentaire