I’m confused about the limit on integer strings passed into std::stoi. An integer is 32-bits am I not mistaken? In a signed 32-bit integer can range from −2,147,483,648 to 2,147,483,647. I’ve input “300000000” (three hundred million) into it and got an out of range exception thrown. It seems like its enforcing a 16-bit limit. std::stol seems to work on the other hand. I’ve been trying to find some documentation that states the limits of these functions but I don’t seem to be able to.
I’m confused about the limit on integer strings passed into std::stoi . An integer
Share
It’s not the functions that impose limits, but the integral types themselves; the functions throw an exception if the input is too large to fit. To see what the maximum and minimum values are for any integral type, use
std::numeric_limits<the_type>::max()andstd::numeric_limits<the_type>::min().