如何将int转换为字符串

时间:2015-03-29 18:52:54

标签: c++ string c++11 int

我这是将int转换为字符串的好方法吗?

    int a = 123456789;
    string str = static_cast<ostringstream*>(&(ostringstream()<<a))->str();

1 个答案:

答案 0 :(得分:4)

C ++ 11为此目的引入了std::to_string

int a = 123456789;
std::string str = std::to_string(a);