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*

5
  • 1
    please updated your stringstream version to include a check for stringstream::fail() (as requested by the questioner "Robust and clear error handling") Commented Oct 11, 2008 at 19:54
  • 2
    Your stringstream version will accept stuff like "10haha" without complaining Commented Nov 13, 2008 at 13:40
  • 3
    change it to (!(ss >> num).fail() && (ss >> ws).eof()) from ((ss >> num).fail()) if you want the same handling like lexical_cast Commented Nov 13, 2008 at 13:42
  • 3
    The C++ with standard library stringstream method doesn't work for strings such as "12-SomeString" even with the .fail() check. Commented Nov 12, 2009 at 15:20
  • C++11 includes standard fast functions for this now Commented Aug 1, 2013 at 15:55