【问题标题】:C++ - Alternative to Integer.parseInt() and String.valueOf() [duplicate]C++ - 替代 Integer.parseInt() 和 String.valueOf() [重复]
【发布时间】:2015-02-27 06:54:43
【问题描述】:

在 C++ 中。 C++中Java的Integer.parseInt()String.valueOf()有什么替代方法。

【问题讨论】:

标签: java c++


【解决方案1】:

对于Integer.parseInt,您可以使用std::stoistd::istringstreamsscanfatoi 等。

对于String.valueOf() 替代品,您可以std::ostringstreamsprintfstd::tostring 等。

推荐:
stoitostring
istringstreamostringstream
atoisprintf

【讨论】:

    【解决方案2】:

    我更喜欢使用sstream

    【讨论】:

      【解决方案3】:

      你可以使用atoi c++函数。

      int atoi (const char * str);
      

      将字符串转换为整数解析 C 字符串 str 解释其 整数形式的内容,它作为类型的值返回 诠释。

      参考:http://www.cplusplus.com/reference/cstdlib/atoi/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-13
        • 2017-03-11
        • 1970-01-01
        • 1970-01-01
        • 2015-08-26
        • 2018-07-18
        • 2018-02-23
        相关资源
        最近更新 更多