C++ Programming Blog

 
 
 

Image

//Conversion CLASS TO BASIC
//String object to basic string

#include <iostream.h>
#include <string.h>
#include <conio.h>

class string
{
  char *p;
  int len;
  public:
   string()
   {}
   string(char *a)
   {
     len=strlen(a);
     p=new char[len+1];
     strcpy(p,a);
   }
   operator char*()
   {
     return(p);
   }
   void display()
   {
     cout<<p;
   }
};


void main()
{
 clrscr();
 string o1=\"vivek\";
 cout<<\"String of Class type : \";
 o1.display();
 cout<<endl;


 char *str=o1;
 cout<<\"String of Basic type : \"<<str;

 getch();
}[/Code]