C++ string swap string value

Description

C++ string swap string value

#include <iostream>
#include <string>
using namespace std;
int main()//from w ww. java 2s. com
{
   string s1("Man");
   string s2 = "test test";
   string s3;
   s3 = s1;                         //assign
   cout << "s3 = " << s3 << endl;
   s3 = "Neither " + s1 + " nor ";
   s3 += s2;
   cout << "s3 = " << s3 << endl;
   s1.swap(s2);                     //swap s1 and s2
   cout << s1 << " nor " << s2 << endl;
   return 0;
}



PreviousNext

Related