标签: c++ string c++11 int
我这是将int转换为字符串的好方法吗?
int a = 123456789; string str = static_cast<ostringstream*>(&(ostringstream()<<a))->str();
答案 0 :(得分:4)
C ++ 11为此目的引入了std::to_string:
std::to_string
int a = 123456789; std::string str = std::to_string(a);