In this article we will discuss how to replace all occurrences of a sub string with new string in C++.

For example, we have a string i.e.

“Boost Library is simple C++ Library”

And we want replace all occurrences of ‘Lib’ with XXX. Let’s see the different methods to do it,

Find & Replace all sub strings – using STL

Output:

Find & Replace all sub strings – using Boost::replace_all

Output:

Find & Replace all Case Insensitive Sub Strings using Boost::ireplace_all

Output: