Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 6
    But they accept arguments than that, one of them being a point to size_t that's, if not null, is set to the first unconverted character Commented Oct 13, 2012 at 10:36
  • 1
    Yes, using the second parameter of std::stoi you can detect invalid input. You still have to roll your own conversion function though... Commented Dec 13, 2012 at 20:56
  • Just like the accepted answer did, but with these standard functions that would be much cleaner, imo Commented Dec 13, 2012 at 22:33
  • 2
    Keep in mind that the second argument in these functions can be used to tell whether the entire string was converted or not. If the resulting size_t isn't equal to the length of the string, then it stopped early. It'll still return 11 in that case, but pos will be 2 instead of the string length 3. coliru.stacked-crooked.com/a/cabe25d64d2ffa29 Commented Jun 22, 2020 at 12:11