What is the difference between std::atoi () and std::stoi?
stackoverflow.com
stoi (): Performs input validation. It throws a std::invalid_argument exception if the input string is not a valid representation of an integer, or a std::out_of_range exception if the converted value exceeds the range of the target type.
What are the differences between std::strtol and std::stoi?
stackoverflow.com
The newer, std::stoi also works directly from std::string (so you don't have to litter your code with .c_str() calls) and optionally provides you the first unmatched character as an index via a size_t, rather than as a pointer.
c++ - Is std::stoi actually safe to use? - Stack Overflow
stackoverflow.com
The problem with stoi is that it succeeds on "123abc", which means it's mostly useless unless you supply and check the ending-index parameter. This makes it even harder to use than strtol because you need to both check the end index, and catch the exception.
How do I validate int input using std::stoi () in C++?
stackoverflow.com
std::stoi converts as much as possible, and only throws an exception if there is nothing to convert. However, std::stoi accepts a pointer parameter representing the start index, which is updated to the character that terminated conversion. See MSDN stoi docs here.