like atoi but to float
问题 Is there a function similar to atoi which converts a string to float instead of to integer? 回答1: atof() (or std::atof() talking C++ - thanks jons34yp) 回答2: boost::lexical_cast<float>(str); This template function is included in the popular Boost collection of libraries, which you'll want learn about if you're serious about C++. 回答3: Convert a string to any type (that's default-constructible and streamable): template< typename T > T convert_from_string(const std::string& str) { std: