c++ replace character in string code example

Example 1: c++ replace character in string

#include 
#include 

void some_func() {
  std::string s = "example string";
  std::replace( s.begin(), s.end(), 'x', 'y'); // replace all 'x' to 'y'
}

Example 2: c++ replace character in string

#include 
#include 

using namespace std;

string test = "abc def abc def"; // The string to replace

// You need to write your part to replace inside the regex(), and write what is the replacement after
test = regex_replace(test, regex("abc"), "Ziv"); // The replacement.

Tags:

Misc Example