What is the best way to convert a string to float(in c++), given that the string may be invalid. Here are the type of input
20.1
0.07
x
0
Do neither and use stringstream.
stringstream
std::stringstream s(str_val); float f; if (s >> f) { // conversion ok } else { // conversion not ok }