forked from teseoch/CPP-Fall-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path81-plus_string.cpp
77 lines (61 loc) · 1.32 KB
/
81-plus_string.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <string>
#include <iostream>
std::string operator+(const std::string &s1, const std::string &s2)
{
std::string res{};
for (auto c : s1)
{
res.push_back(c);
}
for (auto c : s2)
{
res.push_back(c);
}
return res;
}
std::string operator+(const std::string &s, float v)
{
std::string res{};
std::string vstring{std::to_string(v)};
for (auto c : s)
{
res.push_back(c);
}
for (auto c : vstring)
{
res.push_back(c);
}
return res;
}
std::string operator+(const std::string &s, int i)
{
std::string res{};
std::string istring{std::to_string(i)};
for (auto c : s)
{
res.push_back(c);
}
for (auto c : istring)
{
res.push_back(c);
}
return res;
}
int main()
{
std::string A{"Hello"};
std::string B{"World"};
// A.mat_mul(B);
//A@B
int x{42};
float y{3.14};
std::cout << "A plus B: " << (A + B) << std::endl;
// std::cout << "A plus x: " << string_plus_int(A, x) << std::endl;
std::cout << "A plus x: " << (A + x) << std::endl;
// std::cout << "A plus y: " << string_plus_float(A, y) << std::endl;
std::cout << "A plus y: " << (A + y) << std::endl;
std::string res{};
/*Task: make the following work*/
res = A + x;
return 0;
}