資源簡介
自己動手寫一個String實例,可實現基本的讀寫,查找,比較等等功能
代碼片段和文件信息
#define?_CRT_SECURE_NO_WARNINGS
#define?_CRTDBG_MAP_ALLOC
#include?
#include
#include
#include???//用于檢測內存泄漏
#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:
//默認無參構造
MyString();
//構造函數
MyString(int?len);
MyString(const?char*?s);
MyString(char?c?int?n);
MyString(const?MyString&?s);
//重載>>運算符只能在類外實現
friend?ostream&?operator<<(ostream&?os?MyString&?s);
//重載<<運算符只能在類外實現
friend??istream&?operator>>(istream&?is?MyString&?s);
//重載==運算符,類外實現
friend?bool?operator==(const?MyString&?s1?const?MyString&?s2);
//重載()運算符
MyString&?operator()(const?MyString&?str);
//重載=運算符
MyString?operator=(const?MyString&?str);
//重載+運算符
MyString?operator+(const?MyString&?str);
//重載[]運算符
char&?operator[](int?index);
//重載<運算符
bool?operator<(const?MyString&?str2);
//重載<=運算符
bool?operator<=(const?MyString&?str2);
- 上一篇:CRC校驗函數(僅一個函數)
- 下一篇:寧波市中小學程序設計比賽試題及評測數據
評論
共有 條評論