swap [C++ Reference]
Keywords: string,swap
Date: 2010-03-11T02:26:17-0800

## swap

Syntax:

        #include <string>
        void swap( string& from );

The swap() function exchanges the elements of the current string with those of from. This function operates in constant time. For example, the following code uses the swap() function to exchange the values of two strings:

         string first( "This comes first" );
         string second( "And this is second" );
         first.swap( second );
         cout << first << endl;
         cout << second << endl;

The above code displays:

         And this is second
         This comes first