Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class STRING{
- public:
- int len;
- char *name;
- friend istream & operator>>(istream &,const STRING &);
- friend ostream & operator<<(ostream &,const STRING &);
- void ranswap(string a,string b);
- STRING(){len=0; name= new char[len];}
- STRING (const char *w)
- {
- len=strlen(w);
- name= new char [len+1];
- strcpy(name,w);
- }
- STRING(const STRING &a)
- {
- len=a.len;
- name=new char[len+1];
- strcpy(name,a.name);
- }
- };
- void STRING :: ranswap(string a,string b)
- { int i,j=0;
- STRING s;
- len=a.size()+b.size();
- name=new char [len+1];
- for(i=0;i<len;i++)
- {
- if(i%2==0)
- s[i]=a.at(j);
- else
- s[i]=b.at(j);
- j++;
- }
- cout <<s;
- }
- istream & operator>>(istream &in,const STRING &g)
- { delete [] g.name;
- in>>g.name;
- return (in);
- }
- ostream & operator<<(ostream &out,const STRING &k)
- {
- out<<k.name;
- return (out);
- }
- int main()
- {
- STRING s="hello";
- STRING a,n,q,h=" ";
- a=s;
- n="hello";
- cout << n;
- q="world";
- h.ranswap(n,q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement