Answer to Question #193019 in C++ for Ajith M

Question #193019

Write an overloaded function to concatenate two strings using + operator overloading.


1
Expert's answer
2021-05-15T07:31:30-0400
#include <iostream>
#include <string>
using namespace std;




class String {
private:
	string str;
public:	
	String(string str){
		this->str=str;
	}	
	~String(){}
	// overloaded function to concatenate two strings using + operator overloading.
	string operator+(const String& other) {
		return str.append(other.str);
	}
};




int main(){
	
	String string1="I like ";
	String string2="programming";
	string sum=string1+string2;
	cout<<sum<<"\n\n";




	system("pause");
	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog