// Removes words from a string.
// Version 1.0
// Date 17:37 08/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
#include <vector>

using namespace std;
using std::cout;
using std::endl;

string RemoveWord(string src, string RepWord){
	vector<string>words;
	string sWord = "";
	string Buffer = "";
	int i = 0;

	//Append last space so we can get the last word.
	if (!src[src.length() - 1] != '\ '){
		src += " ";
	}

	//Split the words into a vector.
	while (i < src.length()){
		if (src[i] == '\ '){
			//Compare sWord to RepWord
			if (strcmp(sWord.c_str(), RepWord.c_str()) != 0){
				words.push_back(" " + sWord);
			}
			//Clear buffer
			sWord.clear();
		}
		else{
			sWord += src[i];
		}
		i++;
	}

	i = 0;

	//Join the words in the vector into Buffer
	while (i < words.size()){
		//Join words.
		Buffer += words[i];
		i++;
	}

	//Erase the first leading space.
	Buffer.erase(0, 1);
	//Clear up
	words.clear();

	return Buffer;
}

int main(int argc, char *argv[]){
	string sText = "We had the best walk in the park today the weather was fantastic";
	cout << "Source: " << sText.c_str() << endl << endl;
	cout << "Remove the words 'the'" << endl << endl;
	//Print out changed string.
	cout << "New String: " << endl;
	cout << RemoveWord(sText, "the").c_str() << endl;

	system("pause");
	return 0;
}