- string转int:
stoi()函数
- int转string
to_string()函数
- char转int
-‘0’
- int转char
+‘0’
#include<iostream>
#include<string>
using namesapce std;
int main() {
/* ->string to int<- */
string s = "1234";
int n = stoi(s);
cout << n << endl;
/* ->int to string<- */
n = 1234;
s = to_string(n);
cout << s << endl;
/* ->char to int<- */
char c = '2';
n = c - '0';
cout << n << endl;
/* ->int to char<- */
n = 5;
c = n + '0';
cout << c << endl;
cout << "int and char, one -'0' and another +'0'"<<endl;
system("pause");
return 0;
}
//输出
1234
1234
2
5
int and char, one -'0' and another +'0'