【问题标题】:How to convert int to string [duplicate]如何将int转换为字符串[重复]
【发布时间】:2015-06-02 17:05:33
【问题描述】:

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

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

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

  • 请不要回答明显的重复。
猜你喜欢
  • 2015-06-18
  • 2017-05-07
  • 1970-01-01
  • 2020-07-27
  • 2012-01-24
  • 2013-11-04
  • 2021-12-25
  • 2016-07-07
  • 1970-01-01
相关资源
最近更新 更多