How do I Search/Find and Replace in a standard string?

Using boost::replace_all:

#include <boost/algorithm/string.hpp> // include Boost, a C++ library
...
std::string target("Would you like a foo of chocolate. Two foos of chocolate?");
boost::replace_all(target, "foo", "bar");

Leave a Comment