Pages

Monday, August 1, 2011

String Concatenation Using + operator

#include "stdio.h"
#include "conio.h"
#include "string.h"
class string
{
                char str[20];
public:
                string()
                {}
                string(char s[])
                {
                                strcpy(str,s);
                }
                void print()
                {
                                cout<<"\n"<
                }
                string operator+(string s)
                {
                                string temp;                                                     strcpy(temp.str,str);                              
                           strcat(temp.str,s.str);                               
                         return temp;
                }
};

 void main()
{
                clrscr();
                string s1("Operator"),s2("Overloading"),s3;
                s3=s1+s2;
                s3.print();
}

Output

OperatorOverloading

0 comments:

Post a Comment