#include <iostream>
#include<string.h>
#include<string>
using namespace std;
class my_string
{
private:
char *str;
int len;
public:
my_string(){
str=new char[128];
memset(str,0,128);
}
~my_string(){}
//friend my_string operator +(my_string&,my_string&);
friend bool operator >(my_string&,my_string&);
friend bool operator <(my_string&,my_string&);
friend bool operator ==(my_string&,my_string&);
//friend my_string& operator +(my_string&,my_string&);
friend my_string& operator +=(my_string&,my_string&);
my_string(char *s)
{
str = new char[128];
memset(str,0,sizeof(str));
strcpy(str,s);
}
my_string(char s,int n)
{
int i;
str=new char[128];
memset(str,0,sizeof(str));
for(i=0;i<n;i++){
str[i]=s;
}
str[i]='\0';
}
my_string(const my_string& p)
{
this->str=new char[128];
memset(str,0,sizeof(str));
strcpy(this->str,p.str);
this->len=p.len;
}
my_string& operator =(const my_string& R)
{
this->str=new char[128];
memset(str,0,sizeof(str));
strcpy(this->str,R.str);
this->len=R.len;
}
bool my_empty()
{
if(strlen(str)==0)
{
return true;
}
else
{
return false;
}
}
int my_size()
{
cout<<"length:"<<strlen(str)<<endl;
}
char *my_str()
{
return str;
}
//+
my_string operator +(const my_string&R)const
{
my_string tem;
tem.len=this->len+R.len;
strcat(tem.str,this->str);
strcat(tem.str,R.str);
return tem;
}
};
bool operator >(my_string&L,my_string&R)
{
if(strcmp(L.str,R.str)>0)
{
return true;
}
else
{
return false;
}
}
bool operator <(my_string&L,my_string&R)
{
if(strcmp(L.str,R.str)<0)
{
return true;
}
else
{
return false;
}
}
bool operator ==(my_string&L,my_string&R)
{
if(strcmp(L.str,R.str)==0)
{
return true;
}
else
{
return false;
}
}
my_string& operator +=(my_string&L,my_string&R)
{
L.len+=R.len;
return L;
}
int main()
{
my_string s1("hhh"),s2("hjd");
my_string s3=s2;
cout<<"s2>s1?"<<'\t'<<(s2>s1?"yes":"no")<<endl;
cout<<"s2<s1?"<<'\t'<<(s2<s1?"yes":"no")<<endl;
cout<<"s3==s2?"<<'\t'<<(s3==s2?"yes":"no")<<endl;
my_string s4=s1+s2;
cout<<"s4:"<<s4.my_str()<<endl;
cout << "Hello World!" << endl;
return 0;
}