answersLogoWhite

0


Best Answer

#include
using std::cout;
using std::endl;

#include
using std::string;

int main()
{
string s1( "AA" );
string s2( " AAB" );
string s3;

//
cout << "\n\ns1 += s2 yields s1 = ";
s1 += s2; // test overloaded concatenation
cout << s1;
return 0;
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Overload plus operator for string concatenation in coding?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a c plus plus program to use plus operator to display the sum of 2 numbers and concatenation of two strings by using operator overloading?

There is no need to overload the plus operator to achieve this. It is already overloaded with this functionality. #include&lt;iostream&gt; #include&lt;string&gt; int main() { int x=40; int y=2; int z=x+y; std::cout&lt;&lt;x&lt;&lt;" + "&lt;&lt;y&lt;&lt;" = "&lt;&lt;z&lt;&lt;std::endl; std::string s1="Hello "; std::string s2="world!"; std::string s3=s1+s2; std::cout&lt;&lt;"""&lt;&lt;s1.c_str()&lt;&lt;"" + ""&lt;&lt;s2.c_str()&lt;&lt;"" = ""&lt;&lt;s3.c_str()&lt;&lt;"""&lt;&lt;std::endl; return(0); }


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


What is concatetion operation used in java?

"+" is the concatenation operator in Java. It can be used to concatenate two strings. Ex: String firstName = "John"; String lastName = "Morrison"; System.out.println(firstName + " " + lastName); The above code snippet would display John Morrison in the console.


C plus plus program for overloading operator?

#include&lt;iostream&gt; #include&lt;string&gt; // a simple class class my_class { private: std::string m_caption; public: // default constructor my_class (std::string caption): m_caption (caption) {} // read-only accessor const std::string&amp; get_caption() const { return m_caption; } }; // output stream insertion operator overload std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const my_class&amp; obj) { os &lt;&lt; obj.get_caption(); return os; } int main() { // call default constructor my_class object1 ("This is the caption for object1"); // exercise output stream insertion operator overload std::cout &lt;&lt; object1 &lt;&lt; std::endl; }


Write a JavaScript program showing string concatenation?

There isn't much to it:---alert("Hello " + "world!");---'alert' creates a popup, and the + does string concatenation.See related link for a Javascript tutorial.

Related questions

C coding for operator overloading?

C does not support operator overloading. If you mean C++ operator overloading, it depends on exactly what you wanted to do. If you wanted to '+' to strings, then you could write: string operator+(string a, string b) { // do something }


What is a operator overriding in java?

Java does not support object overriding. It does support operator overloading by means of the "+" symbol which is used for both numeric addition as well as string concatenation.


Write a c plus plus program to use plus operator to display the sum of 2 numbers and concatenation of two strings by using operator overloading?

There is no need to overload the plus operator to achieve this. It is already overloaded with this functionality. #include&lt;iostream&gt; #include&lt;string&gt; int main() { int x=40; int y=2; int z=x+y; std::cout&lt;&lt;x&lt;&lt;" + "&lt;&lt;y&lt;&lt;" = "&lt;&lt;z&lt;&lt;std::endl; std::string s1="Hello "; std::string s2="world!"; std::string s3=s1+s2; std::cout&lt;&lt;"""&lt;&lt;s1.c_str()&lt;&lt;"" + ""&lt;&lt;s2.c_str()&lt;&lt;"" = ""&lt;&lt;s3.c_str()&lt;&lt;"""&lt;&lt;std::endl; return(0); }


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


What is concatetion operation used in java?

"+" is the concatenation operator in Java. It can be used to concatenate two strings. Ex: String firstName = "John"; String lastName = "Morrison"; System.out.println(firstName + " " + lastName); The above code snippet would display John Morrison in the console.


C plus plus program for overloading operator?

#include&lt;iostream&gt; #include&lt;string&gt; // a simple class class my_class { private: std::string m_caption; public: // default constructor my_class (std::string caption): m_caption (caption) {} // read-only accessor const std::string&amp; get_caption() const { return m_caption; } }; // output stream insertion operator overload std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const my_class&amp; obj) { os &lt;&lt; obj.get_caption(); return os; } int main() { // call default constructor my_class object1 ("This is the caption for object1"); // exercise output stream insertion operator overload std::cout &lt;&lt; object1 &lt;&lt; std::endl; }


What is concatenation and when will it be useful?

Concatenation is the joining of two vectors to produce a new vector. The new vector simply appends one vector to the other. A vector is an array of variables of the same type. Concatenation is most commonly used to join two strings together (string concatenation). A string is simply an array of type char.


How to perform string operations like concatenation compare etc without using built in functions?

performing string operation using pointers


Write a JavaScript program showing string concatenation?

There isn't much to it:---alert("Hello " + "world!");---'alert' creates a popup, and the + does string concatenation.See related link for a Javascript tutorial.


What is the role of plus operator between two string constant?

The plus operator between string constants allows string concatination: string a = "Hello, "; string b = "World!"; string c = a + b; The output of c would be: "Hello, World!".


C program to copy two strings in to a new string with out using stringcopy in borland c?

You can use so called concatenation of strings:{...string str1 = "something here";string str2 = " and something here";string newStr = str1 + str2;...}


How to write a C program for concatenation of two strings using stack?

#include #include using std::cin;using std::cout;using std::endl;using std::string;int main(void){string str1 = "nothing here";cout str1;string str2 = "neither here";cout str2;string srt = "result here";cout