newbie here. I have two questions.
Firstly, I tried Initializing my vector in this format:
vector<string> v = {"plan", "man", "canal"};
I get this error: in C++98 ‘v’ must be initialized by constructor, not by ‘{...}’
what does it mean by a constructor?
Is it the same with the way I initialized the vector<disliked>
used in the code below?
#include "library/std_lib_facilities.h"
int main()
{
vector<string> disliked;
disliked.push_back("gin");
disliked.push_back("beer");
vector<string> words;
for(string word; cin >> word;)
words.push_back(word);
for(int i = 0; i < words.size(); ++i) {
bool match = false;
for(int x = 0; x < disliked.size(); ++x) {
if(disliked[x] == words[i])
match = true;
}
if(match)
cout << "BLEEP!!" << '\n';
else
cout << words[i] << '\n';
}
}
Secondly, the code works as such:
It takes input and stores them in the vector<words>
when the input is terminated, the for loop
compares both vectors and returns true or false depending on whether any of the vector elements matches.
So my question: is there a simpler or clearer way to write this? Because it seems pertinent to remember if a match is found, because, without it, the nested for loops just prints out the words twice.