Create all combinations of length N from a given alphabet (2)
The generate_words code looks pretty good to me.

Actually, one minor thing - you can return the vector as opposed to passing out by reference. You won't get a performance hit (see move semantics), and it'll make the function easier to use:

auto words = generate_words(letters, word_length);


Some minor observations about the code in main:

1 - As a general rule, you should allocate a vector's memory up front if you know how many elements it will contain. This prevents reallocations from occurring when new elements are inserted into the vector. std::vector provides the reserve method for doing this:

std::vector&lt;char&gt; alphabet;
// allocate memory for at least letter.size() chars
alphabet.reserve(letters.size());
for (const auto &amp;it : letters)
{
    // now you don't have to worry about reallocations happening
    // here
    alphabet.push_back(it);
}


See:

What happens under the hood of vector::push_back memory wise?

std::vector push_back is bottleneck

vector::reserve example code

In this case, you can skip the loop entirely by using std::vector's iterator constructor:

std::vector&lt;char&gt; alphabet(letters.begin(), letters.end());


2 - If you're not using the variable 'letters' after it's been initialized, you could do your sort/unique operation in place:

std::sort(letters.begin(), letters.end());
letters.erase(std::unique(letters.begin(), letters.end()), letters.end());


and then pass letters to generate_words() (you'd have to change the first parameter to a string)