在昨天my_string的基础上将能重载的运算符全部重载
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/228dc6472c0be3843f32943537322389.png)
my_string& operator=(const my_string& Other)
{
this->str = new char[128];
memset(this->str,0,sizeof(this->str));
if(this!=&Other)
{
strcpy(str,Other.str);
}
return *this;
}
bool operator>(my_string& s)
{
if(strcmp(this->str,s.str)>0)
return true;
else
return false;
}
bool operator<(my_string& s)
{
if(strcmp(this->str,s.str)<0)
return true;
else
return false;
}
bool operator==(my_string& s)
{
if(strcmp(this->str,s.str)==0)
return true;
else
return false;
}
bool operator>=(my_string& s)
{
if(strcmp(this->str,s.str)>=0)
return true;
else
return false;
}
bool operator<=(my_string& s)
{
if(strcmp(this->str,s.str)<=0)
return true;
else
return false;
}
bool operator!=(my_string& s)
{
if(strcmp(this->str,s.str)!=0)
return true;
else
return false;
}
my_string& operator +(const my_string& s)
{
strcat(this->str,s.str);
return *this;
}
char operator [](int i)
{
return this->str[i];
}
测试函数
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/aa326ce5e0672f69034565df52c5b437.png)
测试结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ff5bccdcd4c6b91a764d41e7ef412b31.png)