C++ Program to Concatenate String using Plus Operator Overloading
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// + Operator overloading for string concat
#include<iostream>
#include<string.h>
using namespace std;
class MyString
{
char str[100];
public:
MyString(char str[])
{
strcpy(this->str,str);
}
MyString()
{}
void display()
{
cout<<this->str;
}
MyString operator+(MyString K);
};
MyString MyString ::operator+(MyString K)
{
MyString temp;
strcpy(temp.str,this->str);
strcat(temp.str,K.str);
return temp;
}
int main()
{
system("cls");
MyString M1("Hello Friends ");
MyString M2(" Dataflair CPP Course");
MyString M3;
M3=M1+M2; // M3=M1.operator+(M2)
M3.display();
return 0;
} Did we exceed your expectations?
If Yes, share your valuable feedback on Google

