string类型转换int类型
C语言转换形式:
- ...
- std::string str;
- int i = atoi(str.c_str());
- ...
C++转换形式(C++11):
- ...
- std::string str;
- int i = std::stoi(str);
- ...
同样, 可以使用 stol(long), stof(float), stod(double) 等.
int转string:
int n = 65535;
char t[256];
string s;
sprintf(t, "%d", n);
s = t;
cout << s << endl;