Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class str_plus
- {
- int len;
- char *p;
- public:
- str_plus(char *str);
- str_plus();
- str_plus operator+(char *s);
- str_plus operator=(str_plus ob);
- void show();
- };
- str_plus::str_plus()
- {
- len=1;
- p=(char *)malloc(sizeof(char)*len);
- strcpy(p,"*");
- }
- str_plus::str_plus(char *str)
- {
- len=strlen(str)+1;
- p=(char *)malloc(sizeof(char)*len);
- strcpy(p,str);
- }
- str_plus str_plus::operator+(char *s)
- {
- p=(char *)realloc(p,sizeof(char)*strlen(s));
- strcat(p,s);
- return *this;
- }
- str_plus str_plus::operator=(str_plus ob)
- {
- p=(char *)realloc(p,sizeof(char)*strlen(ob.p));
- strcpy(p,ob.p);
- return *this;
- }
- void str_plus::show()
- {
- cout<<p<<"\n";
- }
- int main()
- {
- int n,k;
- str_plus ob1("mahmud"),ob2("mushi"),ob3();
- //ob2=ob1+"is good ";
- ob1=ob1+" is a good";
- ob2=ob2+" is a good boy";
- // ob3=ob3+"hello world"
- ///this shows error
- ob2.show();
- ob1.show();
- ///after "is a good" unknown random chars
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement