Does anybody know of a convenient means of determining if a string value \"qualifies\" as a floating-point number?
bool IsFloat( string MyString )
{
... e
[EDIT: Fixed to forbid initial whitespace and trailing nonsense.]
#include
bool isFloat(string s) {
istringstream iss(s);
float dummy;
iss >> noskipws >> dummy;
return iss && iss.eof(); // Result converted to bool
}
You could easily turn this into a function templated on a type T instead of float. This is essentially what Boost's lexical_cast does.