一开始思路不对,后来知道应该用stringstream,但stringstream掌握的不好。
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
// freopen("xxx.in","r",stdin);
// freopen("yyy.out","w",stdout);
stringstream ss;
string s;
getline(cin,s);
string n;
ss<<s;
string a,b;
cin >> a;
cin >> b;
while(ss>>n)
{
if(n==a)
n=b;
cout << n << " ";
}
// fclose(stdin);
// fclose(stdout);
return 0;
}