Syntax:
#include <string> void swap( string& from );
swap()関数は、 “from”文字列と現在の文字列を入れ替えます。 swap() の実行時間は、一定時間です。
例えば、次のコードは、swap()関数を使って2つの文字列を入れ替えています。
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