swap (<string>)

Permute les tableaux de caractères de deux chaînes.

template<class Traits, class Allocator>
   void swap(
      basic_string<CharType, Traits, Allocator>& _Left,
      basic_string<CharType, Traits, Allocator>& _Right
   );

Paramètres

  • _Left
    Une chaîne dont les éléments doivent être échangés avec celles d'une autre chaîne.

  • _Right
    L'autre chaîne dont les éléments doivent être échangés avec la première chaîne.

Notes

La fonction de modèle exécute le _Left spécialisé de fonction membre.échange(_Right) pour les chaînes, ce qui garantit la complexité constante.

Exemple

// 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;
}
  
  
  
  

Configuration requise

en-tête : <string>

l'espace de noms : DST