template <class charT, class traits, class Alloc> void swap (basic_string<charT,traits,Alloc>& x, basic_string<charT,traits,Alloc>& y);
12345678910111213141516171819
// swap strings #include <iostream> #include <string> main () { std::string buyer ("money"); std::string seller ("goods"); std::cout << "Before the swap, buyer has " << buyer; std::cout << " and seller has " << seller << '\n'; swap (buyer,seller); std::cout << " After the swap, buyer has " << buyer; std::cout << " and seller has " << seller << '\n'; return 0; }
Before the swap, buyer has money and seller has goods After the swap, buyer has goods and seller has money