Filtering out rude words This program will filter the input by replacing matching bad words with "Bleep!". I'd like the code to be more concise and C++ style where possible. One thing that bugs me is the was_bad flag I think is needed to skip printing a word that has matched one of my bad words - if there was some better way to skip the rest of the while loop upon encountering a bad word so I don't print Bleep! poop, for instance.

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

int main(void) 
{
    int i, was_bad = false;
    string input, bad[] = {"poop", "balls"};
    vector &lt;string&gt; badwords(bad, bad + sizeof(bad) / sizeof(string));

    while (cin &gt;&gt; input)
    {
        for (i = 0; i &lt; badwords.size(); ++i)
            if (badwords[i] == input)
            {
                cout &lt;&lt; "Bleep! ";
                was_bad = true;
                break;
            }

        if (!was_bad)
            cout &lt;&lt; input &lt;&lt; " ";

        was_bad = false;
    }

    return 0;
}


One thing that did strike me was to use a ternary operator:

while (cin &gt;&gt; input)
{
    for (i = 0; i &lt; badwords.size(); ++i)
        if (badwords[i] == input)
        {
            is_bad = true;
            break;
        }

    cout &lt;&lt; (is_bad ? "Bleep! " : input + " ");

    is_bad = false;
}
Instead of iterating over a vector I'd use std::find().
Even better, instead of std::vector I'd use std::set:

#include &lt;iostream&gt;
#include &lt;set&gt;
#include &lt;string&gt;

using namespace std;

int main(int argc, const char * argv[])
{
    string bad[] = {"poop", "balls"};
    set&lt;string&gt; bad_words(bad, bad + sizeof(bad) / sizeof(string));

    string input;
    while(cin &gt;&gt; input)
    {
        if(bad_words.find(input)!=bad_words.end()){
            cout &lt;&lt; "bleep! ";
        }
        else {
            cout &lt;&lt; input &lt;&lt; " ";
        }
    }
}