swap函数的函义
来源:百度知道 编辑:UC知道 时间:2024/09/28 09:27:51
002
swap函数很多的,在不同领域,大同都是交换的意思。比如字符串
交换(swap)
语法:
void swap( basic_string &str );
swap()函数把str和本字符串交换。例如:
string first( "This comes first" );
string second( "And this is second" );
first.swap( second );
cout << first << endl;
cout << second << endl;
显示:
And this is second
This comes first