美文网首页
c++ int转字符串

c++ int转字符串

作者: 送分童子笑嘻嘻 | 来源:发表于2019-11-06 15:51 被阅读0次

C++ 字符串转int

转载 小雷叔叔 发布于2018-06-26 07:59:49 阅读数 4845 收藏

展开

<article class="baidu_pl">

1.C++风格的流

include<sstream>;
stringstream stream;
int number = 0;string text("13");
stream << text;stream >> number ;
stream.clear();
//转换后字符串还保留在流中,需使用手动清空

2.C风格的atoi()函数

int number = 0;
string text = "13";
number = atoi(text.c_str());

3 .tostring

int number = 1
string result = tostring(number)

相关文章

网友评论

      本文标题:c++ int转字符串

      本文链接:https://www.haomeiwen.com/subject/cfiubctx.html