【问题标题】:How to convert Integer to string [duplicate]如何将整数转换为字符串[重复]
【发布时间】:2012-06-28 16:41:58
【问题描述】:

可能重复:
Alternative to itoa() for converting integer to string C++?
How to convert a number to string and vice versa in C++
Append an int to a std::string

我想将整数转换为字符串,有人帮我做这些转换吗?

itoa(*data->userid,buff1,10);
itoa(*data->userphone,buff2,10);

【问题讨论】:

标签: c++ c pointers


【解决方案1】:

如果你有一个带有新 std::to_string 函数的 C++11 编译器,你可以使用它。否则使用 Luchian 的std::stringstream 解决方案。

【讨论】:

    【解决方案2】:

    对于 C++,请改用 std::stringstream

    #include <sstream>
    
    //...
    std::stringstream ss;
    ss << *data->userid;
    std::string userId = ss.str();
    

    std::to_string,如果您可以访问 C++11 编译器。

    【讨论】:

      猜你喜欢
      • 2010-11-21
      • 2013-10-06
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 2016-03-16
      相关资源
      最近更新 更多