#include<stdlib.h> #include<stdio.h> #include<sstream> #include<iostream> using namespace std; int main(int argc,char** argv) { //char* to int char* str="12343241"; int n=atoi(str); cout<<"1:"<<n<<endl; //string to int string str1="12343241"; int n1=atoi((char*)(str)); cout<<"2:"<<n1<<endl; //string to int stringstream s; string str2="12343241"; int n2; s<<str2; s>>n2; cout<<"3:"<<n2<<endl; //int to string int n3=12343241; char t[256]; string str3; sprintf(t,"%d",n3); str3=t; cout<<"4:"<<str3<<endl; //int to string stringstream s1; int n4=12342341; string str4; s1<<n4; s1>>str4; cout<<"5:"<<str4<<endl; return 0; }
C++中string <-> int
原创
©著作权归作者所有:来自51CTO博客作者宇宙星河的原创作品,请联系作者获取转载授权,否则将追究法律责任
C++中string <-> int
https://blog.51cto.com/yuzwei/1661935
C++中string <-> int
https://blog.51cto.com/yuzwei/1661935
上一篇:C语言中可打印字符
下一篇:Count and Say
举报文章
请选择举报类型
内容侵权
涉嫌营销
内容抄袭
违法信息
其他
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C++第16周项目3 -电子词典
】电子词典 做一个简单的电子词典。在文件dictionary.txt中,保存的是英汉对照的一个词典,词汇量近8000个,英文、中文释义与词
#include javascript ios -
【c++常用排序算法】
【文末评论可以抽奖哦】学习C++,必须会用的排序算法:sort -- random_shuffle --merge -- reverse
C++ #include 迭代器 ios -
如何编译生成dll文件以及如何调用dll文件
1.vs2015下生成DLL文件文件->新建->项目点击确定选择dll选项和空项目选项点击完成为项目添加c++源文件mydll.cpp extern"C"// 此处e
c++ 编译生成dll 调用dll 函数指针 #include -
第5章 语句【C++】
C++ 条件语句、迭代语句、跳转语句、try语句块和异常处理
c++ visual studio 开发语言 #include ios -
第6章 函数【C++】
第6章 函数在前面我们已经使用过定义main函数,以及也见过其他的自定义函数,函数是一个命名了的代码块,我们通过调用
c++ 开发语言 #include ios 函数声明