Copy The Contents Of One String Object To Another String Object

overload  operator to copy the contents of one string object to another string object


Write an OOP program to overload = operator to copy the contents of one string object to another string object.

SOURCE CODE ::
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class string
{
     char s1[20];
    public:
     void get()
     {
    cout<<"\n\n Enter any string : ";
    gets(s1);
     }
     void show()
     {
    cout<<"\n\n The copied String is : ";
    puts(s1);
    cout<<"\n\n";
     }
   void operator =(string x)
     {
       strcpy(s1,x.s1);
     }
};
void main()
{
  string obj,obj1;
  clrscr();
  obj.get();
  obj1.get();
  obj=obj1;
  obj.show();
  getch();
}
OUTPUT ::
 Enter any string : HAPPY
 Enter any string : BIRTHDAY
 The copied String is : BIRTHDAY

Labels: