Possible Duplicate:
Convert double to string C++?
however, thanks everyone, I have a float number:1.000, how to convert it to a std::string ,like "1.000".
Possible Duplicate:
Convert double to string C++?
however, thanks everyone, I have a float number:1.000, how to convert it to a std::string ,like "1.000".
std::stringstream stream;
float f = 1.000f;
stream << f;
std::string str;
stream >> str;
You can either use stringstream
:
float val = 1.000f;
stringstream ss;
ss << val;
string stringVal = ss.str();
or use boost::lexical_cast<>()
(which also uses stringstream underneath)
#include <boost/lexical_cast.hpp>
float val = 1.000f;
string stringVal = boost::lexical_cast<string>( val );