#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string str = "1234";
int n = atoi(str.c_str());//字符串转化为整数
cout << n+1 << endl;
stringstream ss;
ss << n;
ss >> str;//整数转化为字符串
cout << str+"1" << endl;
}
结果如下:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string str = "1234";
int n = atoi(str.c_str());//字符串转化为整数
cout << n+1 << endl;
stringstream ss;
ss << n;
ss >> str;//整数转化为字符串
cout << str+"1" << endl;
}
结果如下: