-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_05.cpp
More file actions
44 lines (44 loc) · 797 Bytes
/
Practice_05.cpp
File metadata and controls
44 lines (44 loc) · 797 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
// Write a program that overloads arithmetic addition operator + for concatenating two string values.
#include<iostream>
#include<string>
using namespace std;
class String
{
private:
string cat;
public:
String()
{
cat = "";
}
void in()
{
cout<<"Enter String: ";
getline(cin, cat);
}
void show()
{
cout<<cat<<endl;
}
String operator +(String s)
{
String temp;
temp.cat = cat + s.cat; // use std::string concatenation
return temp;
}
};
int main()
{
String s1, s2, s3;
s1.in();
s2.in();
cout<<"s1 = ";
s1.show();
cout<<"s2 = ";
s2.show();
cout<<"Concatenating s1 and s2 in s3..."<<endl;
s3 = s1 + s2;
cout<<"s3 = ";
s3.show();
return 0;
}