copy constructor : string « String « C++






copy constructor

  
 

#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

int main()
{
   string s1( "AA1234567890asdfasdf" );
   string s2( " AAB" );
   string s3;

   // test copy constructor
   string *s4Ptr = new string( s1 );  
   cout << "\n*s4Ptr = " << *s4Ptr << "\n\n";

   return 0;
}

 /* 

*s4Ptr = AA1234567890asdfasdf


 */       
    
  








Related examples in the same category

1.Define a string variable, assign a value and display it
2.string basics
3.Changing Case in Strings
4.A short string demonstration.A short string demonstration.
5.Extracting Words in Strings Delimited by Whitespace
6.Loop through the string array
7.Char Escapes