C++之swap()函数

来源:互联网 发布:淘宝助手缓存清理 编辑:程序博客网 时间:2024/06/08 01:34

swap()函数用来交换两个字符串的值

int main(){    string s1 = "hello C++";    string s2 = "wu ba ge";    cout << "交换之前" << endl;    cout << "s1:" << s1 << endl << "s2:" << s2 << endl << endl;;    s1.swap(s2);    cout << "交换之后" << endl;    cout << "s1:" << s1 << endl << "s2:" << s2 << endl;    return 0;}

这里写图片描述