次の方法で共有


swap (<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