Concatenating Strings : string concatenation « String « C++






Concatenating Strings

  
#include <iostream>
#include <string>

using namespace std;

int main(){
   string s1( "A " );
   string s1_original( s1 ); 
   string s2( "B " );

   cout << "String 1: " << s1 << endl << "String 2: " << s2;

   s1 += s2; 
   cout << s1;
   s1 = s1_original;
   cout << "String 1: " << s1 << "\nString 2: " << s2;

   s1 += s2.substr( 0, 18 );
   cout << s1;
}
  
    
  








Related examples in the same category

1.overloaded string concatenation operator
2.overloaded string concatenation operator with C-style string
3.Concatenate Using STL string