#include <iostream>
#include<cstring>
using namespace std;
class my_string
{
public:
my_string(){}
my_string(char *s)
{
len=strlen(s);
str=new char[len];
str=s;
}
my_string(const my_string& O)
{
str=O.str;
len=O.len;
}
my_string& operator=(const my_string& R)
{
if(this!=&R)
{
str=R.str;
len=R.len;
}
return *this;
}
void display()
{
cout<<str<<'\t'<<len<<endl;
}
bool my_empty()
{
if(len==0)
return false;
else
return true;
}
int my_size()
{
return len;
}
char *my_str()
{
return (char*)str;
}
bool operator>(const my_string &R)const
{
if(strcmp(this->str,R.str)>0)
return true;
else
return false;
}
bool operator<(const my_string &R)const
{
if(strcmp(this->str,R.str)<0)
return true;
else
return false;
}
bool operator==(const my_string &R)const
{
if(strcmp(this->str,R.str)==0)
return true;
else
return false;
}
bool operator>=(const my_string &R)const
{
if(strcmp(this->str,R.str)==0 || strcmp(this->str,R.str)>0)
return true;
else
return false;
}
bool operator<=(const my_string &R)const
{
if(strcmp(this->str,R.str)==0 || strcmp(this->str,R.str)<0)
return true;
else
return false;
}
bool operator!=(const my_string &R)const
{
if(strcmp(this->str,R.str)==0)
return false;
else
return true;
}
const my_string operator+(my_string &R)const
{
my_string tem;
strcpy(tem.str,this->str);
strcat(tem.str,R.str);
tem.len=strlen(tem.str);
return tem;
}
char operator[](int R)const
{
return (this->str)[R];
}
private:
char *str;
int len;
};
int main()
{
my_string s1("zhangsan"),s3("lisi");
my_string s2(s1);
cout<<"------------------test > < == !=---------------"<<endl;
cout<<(s1>=s3?"yes":"no")<<endl;
cout<<(s1<=s3?"yes":"no")<<endl;
cout<<(s1==s3?"yes":"no")<<endl;
cout<<(s1!=s3?"yes":"no")<<endl;
cout<<"---------------test + -----------------"<<endl;
my_string s4;
s4=s1+s3;
s4.display();
cout<<"---------------test [] ------------------"<<endl;
cout<<"s4[2]="<<s4[2]<<endl;
cout<<"---------------test = ---------------"<<endl;
s1=s3;
s1.display();
s3.display();
/* cout << "Hello World!" << endl;*/
return 0;
}