13-6.cpp

来自「为C++学习者」· C++ 代码 · 共 37 行

CPP
37
字号
#include<iostream.h>
#include<string.h>
class string
{
  char str[50];
public:
   string()
   {
     *str='\0';
   }
   string(char *ptr){strcpy(str,ptr);}
   char *get_str(){return str;}
   int operator<(string s2);
   int operator>(string s2);
   int operator==(string s2);
};
int string::operator<(string s2)
{
  return strcmp(str,s2.str)<0;
}
int string::operator>(string s2)
{
  return strcmp(str,s2.str)>0;
}
int string::operator==(string s2)
{
  return strcmp(str,s2.str)==0;
}
main()
{
 string op1("Hello"),op2("There"),op3("Hello");
 if(op1==op3)cout<<"op1 equals op3\n";
 if(op1>op2)cout<<"op1>op2\n";
 if(op1<op2)cout<<"op1<op2\n";
 return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?