18.5. Swapping strings
Class string provides member function swap for swapping strings. Figure 18.4 swaps two strings.
Figure 18.4. Using function swap to swap two strings.
Lines 1213 declare and initialize strings first and second. Each string is then output. Line 18 uses string member function swap to swap the values of first and second. The two strings are printed again to confirm that they were indeed swapped. The string member function swap is useful for implementing programs that sort strings.