#ifndef _MYSTRING_H
#define _MYSTRING_H
#include<iostream>
using namespace std;
class MyString
{
private:
char *m_data;
int m_length;
public:
MyString();
MyString(char *str);
MyString(int a, char ch);
MyString(const MyString &a);
~MyString();
//重载<< >>运算符,实现为全局函数
friend ostream &operator <<(ostream &out, const MyString &s);
friend istream &operator >>(istream &in, MyString &s);
//重载=运算符
MyString &operator =(char *str);
MyString &operator =(const MyString &s);
//重载[]运算符
char &operator [](int index);
//重载+ +=运算符
MyString &operator +(char *str);
MyString &operator +(const MyString &s);
MyString &operator +=(char *str);
MyString &operator +=(const MyString &s);
//重载== !=运算符
bool operator ==(char *str);
bool operator ==(const MyString &s);
bool operator !=(char *str);
bool operator !=(const MyString &s);
//重载> <运算符
bool operator >(char *str);
bool operator >(const MyString &s);
bool operator <(char *str);
bool operator <(const MyString &s);
};
#define _MYSTRING_H
#include<iostream>
using namespace std;
class MyString
{
private:
char *m_data;
int m_length;
public:
MyString();
MyString(char *str);
MyString(int a, char ch);
MyString(const MyString &a);
~MyString();
//重载<< >>运算符,实现为全局函数
friend ostream &operator <<(ostream &out, const MyString &s);
friend istream &operator >>(istream &in, MyString &s);
//重载=运算符
MyString &operator =(char *str);
MyString &operator =(const MyString &s);
//重载[]运算符
char &operator [](int index);
//重载+ +=运算符
MyString &operator +(char *str);
MyString &operator +(const MyString &s);
MyString &operator +=(char *str);
MyString &operator +=(const MyString &s);
//重载== !=运算符
bool operator ==(char *str);
bool operator ==(const MyString &s);
bool operator !=(char *str);
bool operator !=(const MyString &s);
//重载> <运算符
bool operator >(char *str);
bool operator >(const MyString &s);
bool operator <(char *str);
bool operator <(const MyString &s);
};
#endif
#include"MyString.h"
#include<iostream>
#include<cstring>
using namespace std;
MyString::MyString()
{
m_length = 0;
m_data = NULL;
}
MyString::MyString(char *str)
{
m_length = strlen(str);
m_data = new char [m_length + 1];
strcpy(m_data, str);
m_data[m_length] = '\0';
}
MyString::MyString(int a, char ch)
{