In the following piece of code, due to using a string, I'm unable to input 'word's into the vector 'words', as CTRL+Z (I'm using Windows) ends the program before I'm able to do so. I'm looking for an alternative to CTRL+Z or a way to change this program, that won't result in this problem. The program is meant to bleep out the words
int main()
{
vector<string> bad_words = { };
string word;
cout << "Input words you want to bleep out ";
for (string bad_word; cin >> bad_word;) {
bad_words.push_back(bad_word);
}
vector<string> words;
cout << "Input words you want to check ";
for (; cin >> word;) {
words.push_back(word);
}
for (int i = 0; i < words.size(); ++i) { // for each word in words
bool contains = false; // contains = false
for (string bad_word : bad_words) { // for each bad_word in bad_words
if (word == bad_word)
contains = true;
break;
}
if (contains == true)
cout << "Bleep ";
else
cout << word;
}
}
This is the Exercise:
Write a program that “bleeps” out words that you don’t like; that is, you read in words using cin and print them again on cout. If a word is among a few you have defined, you write out BLEEP instead of that word.
The 'break' in the inner for-loop is for the purpose of exiting the loop. I've added it because I believed that the loop would run infinitely otherwise (word == bad_word no matter how many times you run it)