#include <iostream>
#include <string>
using namespace std;
void Swap(string *x,string *y){
string temp;
temp=*x;
*x=*y;
*y=temp;


}
int main(){
string a,b;
cin>>a>>b;
string *p1=&a;
string *p2=&b;
Swap(p1,p2);
cout<<*p1<<endl<<*p2;
system("pause");
return 0;
}

当然,其实String类中提供了函数swap(a,b),来交换两个字符串,注意函数名是小写!