I want to swap two string without copying all the characters as it takes more time. I think using address of the strings it can be done within O(1) time complexity. But I am not being able to figure it out. Can you help me to do it?
I tried it using address. But there is some syntax error.
#include <bits/stdc++.h>
using namespace std;
int main ()
{
std::string buyer ("money");
std::string seller ("goods");
string *temp;
std::cout << "Before the swap, buyer has " << buyer;
std::cout << " and seller has " << seller << '\n';
cout<< " Before the swap "<<(&buyer)<<" "<<(&seller)<<"\n";
temp=(&buyer); (&buyer)=(&seller); (&seller)=temp;
cout<< " After the address swap "<<(&buyer)<<" "<<(&seller)<<"\n";
swap (buyer,seller);
cout<< " After the built-in swap "<<(&buyer)<<" "<<(&seller)<<"\n";
return 0;
}