#include <iostream>
#include <climits>
void string_replace(std::string &s, const std::string &match,
const std::string &replaces,
unsigned int max_replacements = UINT_MAX) {
int pos = 0;
unsigned int replacements = 0;
while ((pos = s.find(match, pos)) != std::string::npos && replacements < max_replacements) {
s = s.replace(pos, match.length(), replaces);
pos += replaces.length();
replacements++;
}
}
int main() {
std::string s = "c++ c java c++ python c++";
string_replace(s, "c++", "php");
std::cout << s;
}
/*
run:
php c java php python php
*/