#include
using namespace std;
class ownStrcmp
{
public:
ownStrcmp(){}
ownStrcmp(ownStrcmp& rhs);
ownStrcmp(char* instring){ _string = instring;}
void setString(char* instring){ _string = instring;}
char* getString(){return _string ;}
~ownStrcmp(){}
int operator == ( ownStrcmp &rhs);
private:
char* _string;
bool _ret;
};
ownStrcmp::ownStrcmp(ownStrcmp& rhs)
{
_string = rhs._string;
}
int ownStrcmp::operator == ( ownStrcmp &rhs)
{
_ret = true;
if(this == &rhs)
{
return _ret;
}
int i = 0;
while( _string[i] != NULL){ ++i;}
int stringLength = i;
for (int j=0;j
if(_string[j]!=rhs._string[j]) _ret=false;
}
return _ret;
}
int main()
{
ownStrcmp string1("hello world");
ownStrcmp string2("hello world");
if (string1 == string2)
cout<<"result is true"<
cout<<"result is false"<
}
No comments:
Post a Comment