forked from rajansingh20/concatination_string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcatination_string2.cpp
More file actions
46 lines (37 loc) · 843 Bytes
/
concatination_string2.cpp
File metadata and controls
46 lines (37 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// C++ Program to concatenate two string
// using unary operator overloading
#include <iostream>
#include <string.h>
using namespace std;
// Class to implement operator overloading
// function for concatenating the strings
class AddString {
public:
// Classes object of string
char s1[25], s2[25];
// Parameterized Constructor
AddString(char str1[], char str2[])
{
// Initialize the string to class object
strcpy(this->s1, str1);
strcpy(this->s2, str2);
}
// Overload Operator+ to concat the string
void operator+()
{
cout << "\nConcatenation: " << strcat(s1, s2);
}
};
// Driver Code
int main()
{
// Declaring two strings
char str1[] = "Geeks";
char str2[] = "ForGeeks";
// Declaring and initializing the class
// with above two strings
AddString a1(str1, str2);
// Call operator function
+a1;
return 0;
}