📄 11.6.cpp
字号:
#include <iostream.h>
#include <string.h>
class String
{
public:
String()
{ str=NULL; }
String(char *s)
{ str=s; }
friend bool operator >(String &s1,String &s2);
friend bool operator <(String &s1,String &s2);
friend bool operator ==(String &s1,String &s2);
void Print()
{ cout<<str; }
private:
char *str;
};
bool operator >(String &s1,String &s2)
{
if(strcmp(s1.str,s2.str)>0)
return true;
else
return false;
}
bool operator <(String &s1,String &s2)
{
if(strcmp(s1.str,s2.str)<0)
return true;
else
return false;
}
bool operator ==(String &s1,String &s2)
{
if(strcmp(s1.str,s2.str)==0)
return true;
else
return false;
}
void compare(String &s1,String &s2)
{
if(s1>s2)
{
s1.Print();
cout<<'>';
s2.Print();
}
else if(s1<s2)
{
s1.Print();
cout<<'<';
s2.Print();
}
else
{
s1.Print();
cout<<"==";
s2.Print();
}
cout<<endl;
}
void main()
{
String s1("continue"),s2("break"),s3("while"),s4("continue");
compare(s1,s2);
compare(s2,s3);
compare(s1,s4);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -