Answers for "swap function in cpp for strings"

C++
-1

swap string c++

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

  seller.swap (buyer);

  std::cout << " After the swap, buyer has " << buyer;
  std::cout << " and seller has " << seller << 'n';

  return 0;
}
Posted by: Guest on December-19-2020

Browse Popular Code Answers by Language