#include "std_lib_facilities.h"
usingnamespace std;
int main()
{
vector <string> word; //Vector for input
vector <string> bword(6); //Vector for censoring
string in;
bword[0]="shark";
bword[1]="zone";
bword[2]="broccoli";
bword[3]="fox";
bword[4]="nope";
bword[5]="bot"; // The bunch of words that should be censored
cout<<"Ready. (Cntrl+z to terminate loop for Windows)(Cntrl+D for Unix)"<<endl;
while (cin>>in)
word.push_back(in); // Input words
cout<<"Number of words: "<<word.size()<<endl;
sort(word.begin(),word.end()); //Ignore: this only arranges inputs in
//alphabetical order
for (int c=0;c<word.size();++c)
{
if (c==0||word[c-1]!=word[c]&&word[c]!=bword[0]&&word[c]!=bword[1]&&word[c]!=bword[2]&&word[c]!=bword[3]&&word[c]!=bword[4]&&word[c]!=bword[5]) // Conditions for printing word
cout<<word[c]<<endl;
if (word[c]==bword[0]||word[c]==bword[1]||word[c]==bword[2]||word[c]==bword[3]||word[c]==bword[4]||word[c]==bword[5]) // Conditions for "not" printing
cout<<"WHATCH YOUR TOUNGE/KEBOARD"<<endl;
}
return 0;
}
I suggest you use std::find ( http://www.cplusplus.com/reference/algorithm/find/ ) to determine whether a word needs to be censored. It will make your intent much clearer and it will most likely solve your problem.
Example for your code:
1 2 3 4 5 6 7 8
if (std::find(bword.begin(), bword.end(), word[c]) != bword.end())
{
//word needs to be censored
}
else
{
//word does not need to be censored
}
If you are using sort(word.begin(),word.end()); you might as well use std::find. I pretty much gave you the code, if you think it over I'm sure you can figure this out. Hint: it goes in your for-loop.
If you need any further help please come back to us with your attempt of implementing this.