swap (C++ STL <string>)
2 つの文字列の、文字の配列を交換します。
template<class Traits, class Allocator> void swap( basic_string<CharType, Traits, Allocator>& _Left, basic_string<CharType, Traits, Allocator>& _Right );
パラメーター
_Left
もう一方の文字列と要素を交換する 1 つの文字列。_Right
最初の文字列と要素を交換するもう一方の文字列。
解説
このテンプレート関数は、一定の複雑さを保証する特殊化されたメンバー関数 _Left.swap(_Right) を実行します。
使用例
// string_swap.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
// Declaring an object of type basic_string<char>
string s1 ( "Tweedledee" );
string s2 ( "Tweedledum" );
cout << "Before swapping string s1 and s2:" << endl;
cout << "The basic_string s1 = " << s1 << "." << endl;
cout << "The basic_string s2 = " << s2 << "." << endl;
swap ( s1 , s2 );
cout << "\nAfter swapping string s1 and s2:" << endl;
cout << "The basic_string s1 = " << s1 << "." << endl;
cout << "The basic_string s2 = " << s2 << "." << endl;
}
必要条件
ヘッダー: <string>
名前空間: std