#include<iostream>
#include<string>
#include<stdlib.h>
#include <sstream>
using namespace std;
int main()
{
//0.输出以end结束,输出数字.
string a[100];
int i=0;
cin >> a[i];
while (a[i]!="end"){
i++;
cin >> a[i];
}
for (int j = 0; j < i; j++){
const char *temp;
temp = a[j].c_str();
int temp2 = atoi(temp);//1.使用atoi函数将string转int,传入的实质是char*类型
int temp3 = stoi(a[j]);//2.传入的直接是string类型
cout <<temp2<<" ";
cout << temp3 << " ";
}
//3.char使用减法转数字
string temp4 = "123456";
int numoftemp4 = temp4[0] - '0';//好像只能一个一个运算?(我了解到的)
//3.1字符串转数字istringstream
string fox1 = "456878";
istringstream astrr;
astrr.str(fox1);
int jam;
astrr >> jam;
cout << jam;
//4.数字转字符串
int num = 18;
string astr;
astr = to_string(num);//to_string方法
//5.数字转字符串ostringstream方式
ostringstream os;
int num2 = 99;
string astr2;
os << num2;
astr2 = os.str();
cout << astr2 << endl;
//6.char* 转string
char *p = "numof";
string astr3(p);
cout << astr3 << endl;
return 0;
}
atof() 将字符串转换为双精度浮点型值
atoi() 将字符串转换为整型值
atol() 将字符串转换为长整型值
strtod() 将字符串转换为双精度浮点型值,并报告不能被转换的所有剩余数字
strtol() 将字符串转换为长整值,并报告不能被转换的所有剩余数字
strtoul() 将字符串转换为无符号长整型值,并报告不能被转换的所有剩余数字
字符串输出函数puts
字符串输出函数gets
字符串连接函数strcat
字符串复制函数strcpy
测字符串长度函数strlen
待续...
参考博文:
http://www.elecfans.com/pld/HDLyuyanjiyuandaima/579394.html
https://blog.csdn.net/CHENYUFENG1991/article/details/52694387