c++, converting input string to number, failure to convert should not return zero -


this question has answer here:

hi im looking @ string conversion methods in c++ strtol, strtoll, strtoul, atol etc. seems every single 1 of them return 0 (or 0.0) result string impossible convert. assuming 0 valid correct input program how avoid converting nonsense strings 0 , make example them throw exception instead? there ready made functions perform way or have wrap these of own code. explain me might reasons these functions designed (why build in trouble of separating nonsense string parse result hones-to-god "0" string parse results)?

failure indicated setting errno, old-fashioned c way of doing things.

you might find stol , friends more useful - indicate failure throwing exception.

http://en.cppreference.com/w/cpp/string/basic_string/stol


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -