#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class Add{
public:
char *rep;
Add(){}
Add(char *tem){
rep = new char[strlen(tem)+1] ;
strcpy(rep,tem);
}
Add operator + (const Add &rhs)
{
char *temp;
temp= new char[strlen(rep) + strlen(rhs.rep)+1];
temp = strcat(rep,rhs.rep);
return Add(temp);
}
};
int main()
{
cout<<"hello";
Add obj1("pradeep");
Add obj2("bansal");
Add obj3;
obj3 = obj1+obj2;
cout<<obj3.rep;
getch();
return 0;
}
#include
int main()
{
std
::
string a
=
"Hello "
;
std
::
string b
=
"World"
;
std
::
string c
=
a
+
b
;
return( 0 );
}
The C++ standard library already provides string concatenation in <string>. If you wish to cater for a user-defined string T, use the following implementation:
T operator+ (const T& str1, const T& str2) {
T s { str1 }; // copy the first string
s += str2; // append the second string
return s;
}
Note that you must provide an implementation for the T::operator+= member function. Expressing non-member functions in terms of member functions is standard practice and helps ensure consistency between the two.
For a string object, the implementation of T::operator+= should be similar to the following:
T& T::operator+= (const T& str) {
if (reserve() < str.size()) resize (size() + str.size());
for (auto c : str) append (c);
return *this;
}
The exact implementation will depend upon how your string is implemented.
Note that implementing your own string type is a useful exercise while learning the language, but for real-world applications you should use the std::string type provided by the standard library. It is extremely efficient and the class template can cater for any type of character, including user-defined characters. Consult the source code to get a better understanding of how string concatenation should be implemented.
== == === === === === === === Some Body told me that operator overloading is not there because it violates the transparency of java.since there is no hiding of information in java it does support op overloading === === === === === === Pranab Kumar Rana Software Engineer..... === === === ===
a write the algorithm to concatenate two given string
There are 5 operators which cannot be overloaded. They are: * .* - class member access operator * :: - scope resolution operator * . - dot operator * ?:: - conditional operator * Sizeof() - operator Note:- This is possible only in C++.
I will not use operator overloading in C# to do anything. Operator overloading may lead to one operator has more than 1 semantic meaning. For example, we know 1 + 2 yields 3, and "1" + 2 yields "12". I do not like this overloading of the operator + being used for addition in Number hierarchy, while as the concatenation in strings. That is, one operator (+) has 2 significant semantics.And the question "find largest of two object" is too vague - what do you mean "largest"? and object? We know apple and orange are 2 objects, but how do you compare them, and find the largest one?????? (size, price or what???)
I think you mean operation overlord??? It is the American, Canadian and British offensive on Europe in World War 2. They landed in Normandy on 6th June 1944 (Commonly called D-Day, Day of Days or Deliverance Day) and progressed throughout France liberating Paris on the 25th August. This allowed the allies a foothold in Europe.
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 }
Same operator can be used for different purposes like + can be used for addition of two integers and used for concatenate strings.
Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.
== == === === === === === === Some Body told me that operator overloading is not there because it violates the transparency of java.since there is no hiding of information in java it does support op overloading === === === === === === Pranab Kumar Rana Software Engineer..... === === === ===
To concatenate strings in PHP, you use the . (dot) character. For example: $str = "String1" . "String2";
a write the algorithm to concatenate two given string
There are 5 operators which cannot be overloaded. They are: * .* - class member access operator * :: - scope resolution operator * . - dot operator * ?:: - conditional operator * Sizeof() - operator Note:- This is possible only in C++.
I will not use operator overloading in C# to do anything. Operator overloading may lead to one operator has more than 1 semantic meaning. For example, we know 1 + 2 yields 3, and "1" + 2 yields "12". I do not like this overloading of the operator + being used for addition in Number hierarchy, while as the concatenation in strings. That is, one operator (+) has 2 significant semantics.And the question "find largest of two object" is too vague - what do you mean "largest"? and object? We know apple and orange are 2 objects, but how do you compare them, and find the largest one?????? (size, price or what???)
The dot (.) operator in PHP is used to concatenate strings. For instance:$start = "Big";$end = "Bird";echo $start . ' ' . $end;This code would produce the output:Big Bird
I think you mean operation overlord??? It is the American, Canadian and British offensive on Europe in World War 2. They landed in Normandy on 6th June 1944 (Commonly called D-Day, Day of Days or Deliverance Day) and progressed throughout France liberating Paris on the 25th August. This allowed the allies a foothold in Europe.
strcat if u wnt to use strcat then include string.h header file
"+" 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.