代码
#include <iostream>
#include <sstream>//用到stringstream
using namespace std;
//stirng转int
void s2i(string &str, int &num){
stringstream ss;
ss << str;
ss >> num;
}
//int转string
void i2s(int &num, string &str){
stringstream ss;
ss << num;
ss >> str;
}
int main()
{
//测试s2i()
string str = "123";
int num;
s2i(str, num);
cout << num << endl;
//测试i2s()
int num2 = 321;
string str2;
i2s(num2, str2);
cout << str2 << endl;
return 0;
}
测试