MyString.h文件
/***********************************************************
//Copyright (c) 2013 道合|SameIdeal.com All rights reserved.
************************************************************/
#ifndef MYSTRING_H
#define MYSTRING_H #include <iostream>
using namespace std;
class MyString
{
public:
//构造函数
MyString();
MyString(const MyString&);
MyString(const char*);
MyString(const size_t,const char);
//析构函数
~MyString();
//属性
size_t length();//字符串的长度
bool empty();//字符串是否为空
const char* c_str();//返回C风格字符串的指针
//读写操作符
friend ostream& operator<< (ostream&,const MyString&);
friend istream& operator>> (istream&,MyString&);
//‘+’操作符
friend MyString operator+(const MyString&,const MyString&);
//比较操作符
friend bool operator==(const MyString&,const MyString&);
friend bool operator!=(const MyString&,const MyString&);
friend bool operator<(const MyString&,const MyString&);
friend bool operator<=(const MyString&,const MyString&);
friend bool operator>(const MyString&,const MyString&);
friend bool operator>=(const MyString&,const MyString&);
//下标操作符
char& operator[] (const size_t);
const char& operator[] (const size_t)const;
//赋值操作符
MyString& operator=(const MyString&);
//'+='操作符
MyString& operator+=(const MyString&);