title: Generating a wordlist in C++
body: <p>I am trying to figure out how to generate a word list in C++ based on a string of characters given (similar to how <a href="https://sourceforge.net/projects/crunch-wordlist/" rel="nofollow">crunch wordlist</a> works)</p>
  
  <p>I am fairly new to C++ and have only gotten the program to list the characters off one at a time.</p>
  
  <p>I've been searching online for quite some time with not much luck other than finding O(n^2) with not much idea on how to implement it to the program.</p>
  
  <p>Code:</p>
  
  <pre><code>int main() {
      string characters = "abcde";
  
      int length = 5;
      string word = "";
      for(int i = word.length(); i &lt;= length; i++) {
          for(int l = 0; l &lt; characters.length(); l++) {
              word += characters[l];
              cout &lt;&lt; word &lt;&lt; "\n";
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code>a
  b
  c
  d
  e
  </code></pre>
  
  <p>Wanted Result: <a href="http://pastebin.com/tgyUtKfA" rel="nofollow">http://pastebin.com/tgyUtKfA</a></p>
  
  <p>Snippet of result:</p>
  
  <pre><code>a
  b
  c
  d
  e
  aa
  ab
  ac
  ad
  ae
  ba
  bb
  bc
  bd
  be
  ca
  cb
  cc
  cd
  ce
  da
  db
  dc
  dd
  de
  ea
  eb
  ec
  ed
  ee
  aaa
  </code></pre>
  
  <p>(The final result follows that pattern down to "eeeee")</p>