java C++ - Integer.parseInt() 和 String.valueOf() 的替代方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27716799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ - Alternative to Integer.parseInt() and String.valueOf()
提问by Boris
In C++. What are the alternatives to Integer.parseInt()and String.valueOf()of Java in C++.
在 C++ 中。C++ 中 Java 的Integer.parseInt()和String.valueOf()的替代方法是什么?
回答by Mohit Jain
For Integer.parseInt
you can use std::stoi, std::istringstream, sscanf, atoietc.
因为Integer.parseInt
您可以使用std::stoi、std::istringstream、sscanf、atoi等。
For String.valueOf()
alternatives, you can std::ostringstream, sprintf, std::tostringetc.
对于String.valueOf()
替代方案,您可以使用std::ostringstream、sprintf、std::tostring等。
Recommendations:
c++11stoi
and tostring
c++istringstream
and ostringstream
catoi
and sprintf
推荐:
c++11stoi
and tostring
c++istringstream
and ostringstream
catoi
andsprintf
回答by Juned Ahsan
You may use atoi c++ function.
您可以使用 atoi c++ 函数。
int atoi (const char * str);
Convert string to integer Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.
将字符串转换为整数 解析 C 字符串 str ,将其内容解释为整数,该整数作为 int 类型的值返回。