string::assign-MemoryGarden's Blog-C++ブログ
8201 ワード
string::swap-huycworkのログ-網易ブログ
string::swap
2010-04-13 18:55:53|分類:CPPREFERENCEプライベートルーム|ラベル:|番号大中小購読する
swap
プロトタイプ:
関数swap()は、現在の文字列とfromの要素を置換する.この関数は定数時間(constant time)で実行する.たとえば、次のコードはswap()を使用して2つの文字列の値を交換します.
コードは出力を生成します.
string::swap
2010-04-13 18:55:53|分類:CPPREFERENCEプライベートルーム|ラベル:|番号大中小購読する
swap
プロトタイプ:
#include <string>
void swap( string& from );
関数swap()は、現在の文字列とfromの要素を置換する.この関数は定数時間(constant time)で実行する.たとえば、次のコードは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