Operator Overloading:-
Concatination of Two Strings
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>
class rv{ public:
char str[20];
rv(){ strcpy(str," ");
}
rv(char s[])
{
strcpy(str,s);
}
rv operator +(rv ss) const
{ cout<<"func called\n";
rv temp;
if((strlen(str)+strlen(ss.str))<20)
{ strcpy(temp.str,str);
strcat(temp.str,ss.str);
}
else
cout<<"Overflow";
return temp;
}
};
void main()
{ clrscr();
rv st1="hello",st2=" ravi",st3;
st3=st1+st2;
cout<<st3.str;
getch();
}
No comments:
Post a Comment