Condividi tramite


swap (<string>)

Scambia le matrici di caratteri di due stringhe.

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

Parametri

  • _Left
    Una stringa dei cui elementi è possibile scambiare con quelli di un'altra stringa.

  • _Right
    Un'altra stringa dei cui elementi è possibile scambiare con la prima stringa.

Note

La funzione di modello esegue il _Left specializzato di funzione membro.scambio(_Right) per le stringhe, che garantisce la complessità costante.

Esempio

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

Requisiti

intestazione: <string>

Spazio dei nomi: deviazione standard