資源簡(jiǎn)介
自己動(dòng)手寫(xiě)一個(gè)String實(shí)例,可實(shí)現(xiàn)基本的讀寫(xiě),查找,比較等等功能
代碼片段和文件信息
#define?_CRT_SECURE_NO_WARNINGS
#define?_CRTDBG_MAP_ALLOC
#include?
#include
#include
#include???//用于檢測(cè)內(nèi)存泄漏
#ifdef?_DEBUG
#ifndef?DBG_NEW
#define?DBG_NEW?new?(?_NORMAL_BLOCK??__FILE__??__LINE__?)
#define?new?DBG_NEW
#endif
#endif??//?_DEBUG
using?namespace?std;
class?MyString
{
public:
//默認(rèn)無(wú)參構(gòu)造
MyString();
//構(gòu)造函數(shù)
MyString(int?len);
MyString(const?char*?s);
MyString(char?c?int?n);
MyString(const?MyString&?s);
//重載>>運(yùn)算符只能在類外實(shí)現(xiàn)
friend?ostream&?operator<<(ostream&?os?MyString&?s);
//重載<<運(yùn)算符只能在類外實(shí)現(xiàn)
friend??istream&?operator>>(istream&?is?MyString&?s);
//重載==運(yùn)算符,類外實(shí)現(xiàn)
friend?bool?operator==(const?MyString&?s1?const?MyString&?s2);
//重載()運(yùn)算符
MyString&?operator()(const?MyString&?str);
//重載=運(yùn)算符
MyString?operator=(const?MyString&?str);
//重載+運(yùn)算符
MyString?operator+(const?MyString&?str);
//重載[]運(yùn)算符
char&?operator[](int?index);
//重載<運(yùn)算符
bool?operator<(const?MyString&?str2);
//重載<=運(yùn)算符
bool?operator<=(const?MyString&?str2);
評(píng)論
共有 條評(píng)論