What is the difference between std::atoi() and std::stoi?

1). Are there any other differences between the two? I find std::atoi() a horrible function: It returns zero on error. If you consider zero as a valid input, then you cannot tell whether there was an error during the conversion or the input was zero. That’s just bad. See for example How do I tell if the c … Read more

How to convert a string to integer in C?

There is strtol which is better IMO. Also I have taken a liking in strtonum, so use it if you have it (but remember it’s not portable): You might also be interested in strtoumax and strtoimax which are standard functions in C99. For example you could say: Anyway, stay away from atoi: The call atoi(str) … Read more