String Simple implementation

Source: Internet
Author: User

Namespace ss{class String {friend ostream& operator << (ostream&, const string&);    Char *_str;        Public:string (): _str (new char[1]) {_str[0] = ' + ';        } string (const char* str): _str (new Char[strlen (str) +1]) {strcpy (_str, str);        } string (const string & S): _str (New Char[s.size () +1]) {strcpy (_str, S._STR);        } string (string&& s): _str (s._str) {s._str = nullptr;            }//operator String & operator = (string s) {swap (s);        return *this;        } char & operator [] (int i) {return _str[i];}         /* String &operator = (Const string &s) {if (this = &s) {delete []_str;         if (s._str!= nullptr) {_str = new Char[strlen (S._STR) +1];         strcpy (_str, S._STR);         }} return *this;       }*///get size_t size () const {     return strlen (_STR);        }//Void swap (string& s) {Std::swap (_str, S._STR);    }    };        ostream& operator << (ostream& os, const string &ob) {OS << ob._str;    return OS; }    };

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

String Simple implementation

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.