USING OVERLOADING '+' OPERATOR TO CONCATENATE TWO STRING OBJECT

 /*

USING OVERLOADING '+' OPERATOR TO CONCATENATE TWO STRING OBJECT
*/

#include <iostream>
#include <cstring>

class string{
public:
    char s[20];
    int size;

    void getstring(char str[])
    {
        strcpy(s,str);
    }

    void operator+(string);
};

void string::operator+(string ob)
{
strcat(s,ob.s);
std::cout<<"\nConcatenated String is: "<<s;    
}
int main()
{
    string ob1,ob2;
    char string1[10],string2[10];
    std::cout<<"Enter First string: ";
    std::cin>>string1;
    ob1.getstring(string1);
    std::cout<<"\nEnter second string: ";
    std::cin>>string2;
    ob2.getstring(string2);
    ob1+ob2;
}

/*
Enter First string: Shout
Enter second string: coders
Concatenated String is: Shoutcoders

*/

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES