STL string Instantiation and Copy Techniques : string copy « String « C++






STL string Instantiation and Copy Techniques

  
#include <string>
#include <iostream>
using namespace std;

int main ()
{
   const char* pChar = "Hello String!";
   cout << pChar << endl;

   std::string strFromConst (pChar);
   cout << strFromConst << endl;

   std::string str2 ("Hello String!");
   std::string str2Copy (str2);
   cout << str2Copy << endl;

   // Initialize a string to the first 5 characters of another
   std::string subString (pChar, 5);
   cout << subString << endl;

   return 0;
}
  
    
  








Related examples in the same category

1.Copy char array from a string to a char pointer
2.Copying Strings
3.Initializing, Assigning (Copying), and Concatenating Strings Using std::string