1.string转换成其它类型
string s;
(1)string转换成int
int a=stoi(s);
如果遇到非法输入,stoi会自动截取最前面的数字,直到遇到不是数字为止
所以说如果是浮点数,会截取前面的整数部分
(2)string转换成double
double a=stod(s);
如果是非法输入,stod会截取最前面的浮点数,直到遇到不满足浮点数为止
(3)string转换成float
float a=stof(s);
2.int,float,double转换成string
int a;或者float a;或者double a;
string s=to_string(a);
stringstream方法
int aa = 30;
stringstream ss;
ss<<aa;
string s1 = ss.str();
cout<<s1<<endl; // 30
3.int转换为double,float类的
int a;
double b=(double)a;