String class default constructor

Source: Internet
Author: User

#include <iostream>//using namespace std;//#pragma  warning (disable :4996)//class   string//{//public:///*string ()//:_str (New char[strlen ("") +1])//{//*_str =  '//}/'; /string (const char*s)//:_str (New char[strlen (s)  + 1])//{//strcpy (_str, s);//}*/// String (const char* s =  "")//:_str (New char[strlen (s)  + 1])//{//strcpy (_STR,  s)//}//string (const string& s)//:_str (new char[(strlen (S._STR)) +1])//{//strcpy (_STR, &NBSP;S._STR);//}//string& operator= (const string& s)//{//if  (this !=  &s)//{//delete[] _str;//need to release the original space when re-assigned, otherwise memory leaks//_str = new char[(strlen (_STR))  +  1];//strcpy (_STR,&NBSP;S._STR);//}//return *this;//}////~string ()//{//delete[] _str;//}//void  display ()//{//cout << _str << endl;//}//private://char* _str;//};// Void test1 ()//{///*string s1;//s1. Display ();////string s2 (S1);//s2. Display (); */////STRING&NBSP;S1 ("ABCD");//s1. Display ();//string s2;//s2. Display ();////s2 = s1;//s2. Display ();//////}//int main ()//{//test1 ();//system ("pause");//return 0;//}

Be aware of memory management, easy memory leaks Oh!

This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1715708

String class default constructor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.