answersLogoWhite

0

#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

15y ago

What else can I help you with?

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.


What is the significance of closed under concatenation in the context of string operations?

In the context of string operations, being closed under concatenation means that when you combine two strings together, the result is still a valid string. This property is important because it ensures that string operations can be performed without creating invalid or unexpected results.


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


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!".


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.


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;...}