If s is a std::string, then is there a function like the following?
s.replace(\"text to replace\", \"new text\");
Yes: replace_all is one of the boost string algorithms:
Although it's not a standard library, it has a few things on the standard library:
replace_all nested inside a trim). That's a bit more involved for the standard library functions.