Do you know what you actually wrote here?
if (word == disliked[0, 1])
disliked[1] for equality with disliked[1] . Because a comma is an operator for sequential execution of instructions; as a result, the last value is taken. You got two instructions in square brackets - 0 (which is ignored, and about which the compiler should have issued a warning) and 1 , which becomes the result ...
And that's what you wanted to write :) -
more briefly, using std::find from <algorithm> :
while (cout << "Enter the word: ", cin >> word) { // Проверка, есть ли слово word в векторе if (find(disliked.begin(), disliked.end(),word) != disliked.end()) cout << "BEEEP!!" << endl; else cout << "You entered " << word << endl; }
Please note that here is while (cout << "Enter the word: ", cin >> word) - I used the comma-operator mentioned above to ask for a word for each word, but not once for all the words entered.
It is possible in more detail, so that it would be clearer to you - just go through the elements using a loop:
while (cout << "Enter the word: ", cin >> word) { bool found = false; // Флаг, что слово найдено for(size_t i = 0; i < disliked.size(); ++i) // Проход по всем словам if (word == disliked[i]) // Если найдено { found = true; // выставляем флаг и break; // покидаем цикл (дальше искать не смысла) } if (found) // Было найдено cout << "BEEEP!!" << endl; else cout << "You entered " << word << endl; }
About Russian letters - see the answers to this question: Russian language in the console