Porting Python algorithm to C++ - different solution
<p>Thank you all for helping. Below this post I put the corrected version's of both scripts which now produce the equal output. </p>

<hr>

<p>Hello,</p>

<p>I have written a little brute string generation script in python to generate all possible combinations of an alphabet within a given length. It works quite nice, but for the reason I wan't it to be faster I try to port it to C++. </p>

<p>The problem is that my C++ Code is creating far too much combination for one word.
Heres my example in python:</p>

<p><code>./test.py</code></p>

<p>gives me</p>

<pre>aaa
aab
aac
aad
aa
aba
....</pre>

<p>while <code>./test</code> (the c++ programm gives me)</p>

<pre>aaa
aaa
aaa
aaa
aa</pre>

<p>Here I also get all possible combinations, but I get them twice ore more often.</p>

<p>Here is the Code for both programms:</p>

<pre><code> #!/usr/bin/env python
 import sys
 #Brute String Generator
 #Start it with ./brutestringer.py 4 6 "abcdefghijklmnopqrstuvwxyz1234567890" ""
 #will produce all strings with length 4 to 6 and chars from a to z and numbers 0 to 9
 def rec(w, p, baseString):
    for c in "abcd":
        if (p&lt;w - 1):
            rec(w, p + 1, baseString + "%c" % c)
         print baseString

 for b in range(3,4):
     rec(b, 0, "")
</code></pre>

<p>And here the C++ Code</p>

<pre><code> #include &lt;iostream&gt;
 using namespace std;
 string chars="abcd";

 void rec(int w,int b,string p){
    unsigned int i;
    for(i=0;i&lt;chars.size();i++){
        if(b &lt; (w-1)){
            rec(w, (b+1), p+chars[i]);
        }
        cout &lt;&lt;  p &lt;&lt; "\n"; 
    }
 }


 int main ()
 {
    int a=3, b=0;
    rec (a+1,b, "");
    return 0;
 }
</code></pre>

<p>Does anybody see my fault ? I don't have much experience with C++.</p>

<p>Thanks indeed</p>

<hr>

<p>Here the corrected version:</p>

<p>C++</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
string chars="abcd";

void rec(int w,int b,string p){
    unsigned int i;
    for(i=0;i&lt;chars.size();i++){
        if(b &lt; (w)){
            rec(w, (b+1), p+chars[i]);
        }
    }
    cout &lt;&lt; p &lt;&lt; "\n";
}


int main ()
{
    rec (3,0, "");
    return 0;
}
</code></pre>

<p>Python</p>

<pre><code>#!/usr/bin/env python
import sys

def rec(w, b, p):
    for c in "abcd":
        if (b &lt; w - 1):
            rec(w, b + 1, p + "%c" % c)
    print p

rec(4, 0, "")
</code></pre>

<p>Equal Output:</p>

<pre><code>$ ./test &gt; 1
$ ./test.py 3 3 "abcd" "" &gt; 2
$ diff 1 2
$ 
</code></pre>
