Sunday, July 4, 2010

PROGRAM TO CONCATENATE TWO STRINGS BY OVERLOADING += OPERATOR

Buzz It
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class string
{
char str[100];
public:
void input();
void output();
string operator+(string s);
};
void string::input()
{
cout<<"enter the string\n";
gets(str);
}s
tring string::operator+(string s)
{
string temp;
strcpy(temp.str,str);
strcat(temp.str,s.str);
return(temp);
}
void string::output()
{
cout<<"the string is\n";
cout<<str;
}
void main()
{
string s1,s2,s3;
clrscr();
s1.input();
s2.input();
s3=s1+s2;
s3.output();
getch();
}


OUTPUT:
enter the string
farook
enter the string
college
the string is
farookcollege

0 comments:

Post a Comment