Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<string.h>
- class string
- {
- char *nm;
- int len;
- public:
- string()
- {
- len=0;
- nm=new char[len+1];
- }
- string(char *s)
- {
- len=strlen(s);
- nm=new char[len+1];
- strcpy(nm,s);
- }
- int operator==(string t)
- {
- if(strcmp(nm,t.nm)==0)
- return 1;
- else
- return 0;
- }
- };
- int main()
- {
- char a[10],b[10];
- string s1,s2;
- cout<<"enter two words to compare them\n";
- cin>>a>>b;
- s1=string(a);
- s2=string(b);
- if(s1==s2)
- cout<<"the words are the same\n";
- else
- cout<<"the words are different\n";
- return 0;
- }
- OUTPUT:
- enter two words to compare them
- oops
- oops
- the words are the same
- Press any key to continue
- enter two words to compare them
- oops
- loops
- the words are different
- Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment