Answers for "string swap c++"

C++
0

c++ swap function

int main()
{
	int a = 5;
	int b = 10;
  
	swap(a, b);
  
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
}
Posted by: Guest on May-08-2021
-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