8 lines
325 B
Plaintext
8 lines
325 B
Plaintext
template <typename T>
|
|
T string_to_number (const std::string &text, T def_value) {
|
|
std::stringstream ss;
|
|
for (std::string::const_iterator i = text.begin(); i != text.end(); ++i)
|
|
if (isdigit(*i) || *i=='e' || *i=='-' || *i=='+' || *i=='.') ss << *i;
|
|
T result;
|
|
return ss >> result ? result : def_value;
|
|
} |