#include <iostream>
std::string removeWord(std::string str, std::string word) {
if (str.find(word) != std::string::npos) {
size_t pos = -1;
std::string tmp = word + " ";
while ((pos = str.find(word)) != std::string::npos)
str.replace(pos, tmp.length(), "");
tmp = " " + word;
while ((pos = str.find(word)) != std::string::npos)
str.replace(pos, tmp.length(), "");
}
return str;
}
int main()
{
std::string str = "C++ is a high-level general purpose programming language";
std::string word = "purpose";
str = removeWord(str, word);
std::cout << str;
}
/*
run:
C++ is a high-level general programming language
*/