#include<iostream.h>
#include<string.h>
class String
{public:
String(){
p=NULL;
}
String(char *str);
friend bool operator >(String &string1,String &string2);
friend bool operator =(String &string1,String &string2);
friend bool operator <(String &string1,String &string2);
void display();
private:
char *p;
};
String::String(char *str)
{
p=str;
}
void String::display()
{
cout<<p;
}
bool operator>(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)>0)
return true;
else
return false;
}
bool operator<(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)<0)
return true;
else
return false;
}
bool operator==(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)==0)
return true;
else
return false;
}
int main()
{
String string1("Hello"),string2("Book"),string3("Computer");
cout<<(string1>string2)<<endl;
cout<<(string1<string3)<<endl;
cout<<(string1==string2)<<endl;
return 0;
}
uj5u.com熱心網友回復:
直接#include <iostream>uj5u.com熱心網友回復:
C++的頭檔案不要加.h轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/76008.html
標籤:C++ 語言
