This compiles and runs ok on Visual C++ 2010 Express but it only checks against the [2] element: "Fish".
int main()
{
vector<string> words;
string temp;
vector<string> disliked(3);
disliked[0] = "Broccoli";
disliked[1] = "Mushrooms";
disliked[2] = "Fish";
while (cin >> temp)
words.push_back(temp);
cout << "Number of words: " << words.size() << endl;
for (int i=0; i<words.size(); ++i) {
if (words[i]!=disliked[2])
cout << words[i] << " ";
else cout << "BLEEP" << " ";
}
cout << endl;
keep_window_open();
return 0;
}
How do I make it check against ALL vector elements without typing:
if (words[i]!=disliked[0] && words[i]!=disliked[1] && words[i]!=disliked[2])
? Any other advices of how to make it better or more elegant?