C风格字符串,int型,string类型相互转换
来源:互联网 发布:规则引擎 数据库设计 编辑:程序博客网 时间:2024/06/04 20:02
#include<iostream>
#include<string>
#include <sstream>
using namespace std;
int main(){
//c风格字符串转int
int a= atoi("1024");
cout << a << endl;
//int转c风格字符串
int number = 100;
char str[7];
_itoa(number, str, 10);
cout << str << endl;
//string 转int
/*方法1:atoi c_str() /
string str2 = "1000";
int n = atoi(str2.c_str());
cout << n << endl;
/*方法2: 流实现*/
stringstream ss2;
int n4;
string str4="1235466";
ss2 << str4;
ss2 >> n4;
cout << n4 << endl;
//int 转string
/* 方法1: to_string */
int i = 12;
cout << std::to_string(i) << endl;
/* 方法2: 流实现*/
stringstream ss;
int n1 = 123;
string str3;
ss << n1;
ss >> str3;
cout << str3 << endl;
system("pause");
}
#include<string>
#include <sstream>
using namespace std;
int main(){
//c风格字符串转int
int a= atoi("1024");
cout << a << endl;
//int转c风格字符串
int number = 100;
char str[7];
_itoa(number, str, 10);
cout << str << endl;
//string 转int
/*方法1:atoi c_str() /
string str2 = "1000";
int n = atoi(str2.c_str());
cout << n << endl;
/*方法2: 流实现*/
stringstream ss2;
int n4;
string str4="1235466";
ss2 << str4;
ss2 >> n4;
cout << n4 << endl;
//int 转string
/* 方法1: to_string */
int i = 12;
cout << std::to_string(i) << endl;
/* 方法2: 流实现*/
stringstream ss;
int n1 = 123;
string str3;
ss << n1;
ss >> str3;
cout << str3 << endl;
system("pause");
}
阅读全文
0 0
- C风格字符串,int型,string类型相互转换
- C风格字符串和string类型的相互转换
- C++标准库的string类型与C 风格的字符串的相互转换
- String int类型相互转换
- String类型和int类型相互转换
- 类型转换 CString String int 相互转换
- 完成一程序演示字符数组、C风格字符串、std::string和MFC中的Cstring类型之间的相互转换
- string,char,int类型的相互转换
- String与int类型相互转换
- Java int 与 string类型相互转换
- Java:int、String的类型相互转换
- string 和 int类型的相互转换
- c++string类型转换为int型
- C风格字符串&string类型
- Integer类型、int类型类型、String类型的相互转换
- C++: int和string相互转换
- Java中String类型,int类型,double类型相互转换
- int string相互转换
- Lock wait timeout exceeded; try restarting transaction错误
- npm依赖包 缓存策略详细教程npm_lazy
- qt5.6的安装,手把手详细图文
- Oracle SQLServer MySQL数据库之间的语法差异
- C++中SendMessage与PostMessage的区别
- C风格字符串,int型,string类型相互转换
- sql中的group_concat 和 oracle中的wm_concat
- 异常使用原则
- 对synchronized(this)的一些理解
- Idea 找不到tomcat服务器选项
- PHP远程上传文件
- mybatis中#{}和${}的区别
- android parcelable 详细介绍
- 获取股票数据的2个简单方法