c++ - std::string to int / double in one pass -
i'm parsing string may contain either real or integral value. parse string , either integral or real value in single parsing.
i use std::stoi , std::stod, if call stoi first , real, it's going fail , have call stof, causing second parsing. , if call stof first , string contains integral, it's going consider valid real value, losing information integral.
is there kind of function can parse both types in single pass ? or first have dot manually , call right function ?
thank you. :)
you not find standard call achieve simple reason string of digits without dot both valid integer , valid double.
if criterion "double if , if dot", dot hand. alternatively, read double , check fractional part null.
Comments
Post a Comment