Hi everyone. I have been programming for 2 years so I am pretty new to C++ programming. I have an assignment that I am wishing someone can just explain to me what is needed. Below is my code and here are my questions:
1) I dont quite understand operator overloading. It seems that I am using alternate functions for the - sign below to accomplish the particular output. Can someone please explain operator overloading in this context?
2) In the replace function, I think I am required to use member functions like find, and remove from the string class. Is this correct? As you can see, I am a bit confused at the aim involved here. At the bottom is my required output. Thank you for any guidance.
#include <iostream>
#include <string>
using namespace std;
string operator-(string a, string b)
{
// Complete the implementation of this operator ...
}
void replace(string & base, string pattern, string replacement)
{
// Complete the implementation of this function ...
}
main()
{
string x = "collision";
string y = x - "lisi";
cout << y << endl;
string b = "this is a test in isolation";
string p = "is";
string r = "isn't";
replace(b, p, r);
cout << b << endl;
}
$ a.out
colon
thisn't isn't a test in isn'tolation
$