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


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


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



Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.