upsidedown

string cmp ovrld r.p

Mar 9th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<string.h>
  3.  
  4. class string
  5. {
  6.     char *nm;
  7.     int len;
  8. public:
  9.     string()
  10.     {
  11.         len=0;
  12.         nm=new char[len+1];
  13.     }
  14.  
  15.     string(char *s)
  16.     {
  17.         len=strlen(s);
  18.         nm=new char[len+1];
  19.         strcpy(nm,s);
  20.     }
  21.  
  22.     int operator==(string t)
  23.     {
  24.         if(strcmp(nm,t.nm)==0)
  25.             return 1;
  26.         else
  27.             return 0;
  28.     }
  29. };
  30.  
  31. int main()
  32. {
  33.     char a[10],b[10];
  34.     string s1,s2;
  35.     cout<<"enter two words to compare them\n";
  36.     cin>>a>>b;
  37.     s1=string(a);
  38.     s2=string(b);
  39.     if(s1==s2)
  40.         cout<<"the  words are the same\n";
  41.     else
  42.         cout<<"the words are different\n";
  43.     return 0;
  44. }
  45.  
  46. OUTPUT:
  47. enter two words to compare them
  48. oops
  49. oops
  50. the  words are the same
  51. Press any key to continue
  52.  
  53. enter two words to compare them
  54. oops
  55. loops
  56. the words are different
  57. Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment