In order to convert an int (or any other numeric type, e.g., float, double, etc.) to string, you can use:
#include
int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();
Other not so frequently asked questions.
怎么介绍?
分类:
2008-09-23 08:33:44
string s;
float f;
stringstream ss;
ss << s;
ss >> f;
In order to convert an int (or any other numeric type, e.g., float, double, etc.) to string, you can use:
#include
int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();
Other not so frequently asked questions.
Here’s a more generic version:
#include
template
inline std::string to_string (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}