Concatenate Using STL string : string concatenation « String « C++






Concatenate Using STL string

  
#include <string>
#include <iostream>

int main ()
{
   using namespace std;

   string strSample1 ("Hello");
   string strSample2 (" String!");

   // Concatenate
   strSample1 += strSample2;
   cout << strSample1 << endl << endl;

   string strSample3 (" this is a test");
   strSample1.append (strSample3);
   cout << strSample1 << endl << endl;

   const char* charPointer = "another test";
   strSample1.append (charPointer);
   cout << strSample1 << endl;

   return 0;
}
  
    
  








Related examples in the same category

1.overloaded string concatenation operator
2.overloaded string concatenation operator with C-style string
3.Concatenating Strings