I have a vector of string constructed using:
vector<string> names;
names.push_back("Gates");
names.push_back("Jones");
names.push_back("Smith");
names.push_back("Gates");
I want to replace "Gates" with "Bill", for every occurrence of "Gates". For this the easiest solution I know is to use the replace function from algorithm and use it as:
replace(names.begin(), names.end(), "Gates", "Bill");
But I am getting following error:
parameter type mismatch:incompatible types 'const char (&)[6]' and 'const char[5]'.
I can solve it using implicit type casting like this:
replace(names.begin(), names.end(), "Gates", (const char (&)[6]) "Bill");
Can anyone explain what this error is, and better way to solve it or better way to do it. Or why do we need this type casting.
replace(names.begin(), names.end(), "Gates"s, "Bill"s)which looks a lot better.