Sintaxe:
#include <string> void swap( string& from );
A função swap() troca os elementos da string actual com os elementos de from. Esta função opera em tempo constante. Por exemplo, o código seguinte usa a função swap() para trocar os valores de duas strings:
string first( "This comes first" ); string second( "And this is second" ); first.swap( second ); cout << first << endl; cout << second << endl;
O código acima mostra:
And this is second
This comes first