C++ swap strings


/ Published in: C++
Save to your folder(s)

Swap strings in C++


Copy this code and paste it in your HTML
  1. // swap strings
  2. #include <iostream>
  3. #include <string>
  4.  
  5. main ()
  6. {
  7. std::string buyer ("money");
  8. std::string seller ("goods");
  9.  
  10. std::cout << "Before the swap, buyer has " << buyer;
  11. std::cout << " and seller has " << seller << '\n';
  12.  
  13. seller.swap (buyer);
  14.  
  15. std::cout << " After the swap, buyer has " << buyer;
  16. std::cout << " and seller has " << seller << '\n';
  17.  
  18. return 0;
  19. }

URL: http://www.softafzar.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.