#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Enter a string:\n";
string array_1;
getline(cin, array_1);
cout << "Enter a string you want to find:\n";
string ch;
getline(cin, ch);
cout << "Enter a string you wish to replace " << ch << " with:\n";
string ch2;
cin >> ch2;
for(size_t pos = array_1.find(ch); pos != std::string::npos;
pos = array_1.find(ch, pos))
{
array_1.replace(pos, ch.size(), ch2);
pos += ch2.size();
}
cout << "Here is the new string: " << array_1 << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpCnsKICAgIGNvdXQgPDwgIkVudGVyIGEgc3RyaW5nOlxuIjsKICAgIHN0cmluZyBhcnJheV8xOwogICAgZ2V0bGluZShjaW4sIGFycmF5XzEpOwoKICAgIGNvdXQgPDwgIkVudGVyIGEgc3RyaW5nIHlvdSB3YW50IHRvIGZpbmQ6XG4iOwogICAgc3RyaW5nIGNoOwogICAgZ2V0bGluZShjaW4sIGNoKTsKCiAgICBjb3V0IDw8ICJFbnRlciBhIHN0cmluZyB5b3Ugd2lzaCB0byByZXBsYWNlICIgPDwgY2ggPDwgIiB3aXRoOlxuIjsKICAgIHN0cmluZyBjaDI7CiAgICBjaW4gPj4gY2gyOwoKICAgIGZvcihzaXplX3QgcG9zID0gYXJyYXlfMS5maW5kKGNoKTsgcG9zICE9IHN0ZDo6c3RyaW5nOjpucG9zOwogICAgICAgICAgICAgICBwb3MgPSBhcnJheV8xLmZpbmQoY2gsIHBvcykpCiAgICB7CiAgICAgICAgYXJyYXlfMS5yZXBsYWNlKHBvcywgY2guc2l6ZSgpLCBjaDIpOwogICAgICAgIHBvcyArPSBjaDIuc2l6ZSgpOwogICAgfQoKICAgIGNvdXQgPDwgIkhlcmUgaXMgdGhlIG5ldyBzdHJpbmc6ICIgPDwgYXJyYXlfMSA8PCAnXG4nOwp9Cg==