是否不建议以这种方式转换字符串:
string input = "81.312";
double val = atof(input.c_str());
不要std::atof在 C++ 中使用。这不检查输入错误。
使用std::stod. 这也会检查错误并相应地引发异常。
此外,它std::string const &作为论据。所以你不必通过input.c_str()。只需这样做:
double value = std::stod(input);
这没有错,但更正确的是使用 boost::lexical_cast。
您还应该检查这些工具是否正确处理 NAN 和 INF。