Monday 8 April 2013

C++ Program To Implement == Operator Overloading


#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
private:char s[20];
public:string()
{
}
string(char a[])
{
strcpy(s,a);
}
int operator==(string a)
{
if(strcmp(s,a.s)==0)
return (1);
else
return (0);
}
};
void main()
{
char s1[20],s2[20];
clrscr();
cout<<"ENTER THE FIRST STRING:";
cin>>s1;
string obj1(s1);
cout<<"ENTER THE SECOND STRING:";
cin>>s2;
string obj2(s2);
if(obj1==obj2)
cout<<"TWO STRINGS ARE EQUAL";
else
cout<<"TWO STRINGS ARE NOT EQUAL";
getch();
}

No comments:

Post a Comment