C++ - Moving generated numbers into a string : <p>I have a code that generates some numbers, and now I need to count how frequent they are. For example, the code will generate 100000 numbers, and i need to know how many times does 0 appear, 1, 2... I know that this can be done with strings, but im having a problem turning those values into one big string.
You see, all the generated numbers will be the same variable G, so if a ask to turn G into a string, Im going to have a string of the very last number assigned to G, and not of all of them, that is beacuse the variable G changes value each time its printed, because it is inside a loop. is there any way for me to move ALL the printed values into one big string? (If 100000 is too much for a string, i can generate less numbers with little problem)</p>

<p>This is the code</p>

<pre><code>int a,b,c,d,e,f,g,h,i,k,A,B,C,D,E,F,G;

srand(time(NULL));
int seed = rand();
default_random_engine ran { static_cast &lt;int&gt;( chrono::high_resolution_clock::now().time_since_epoch().count())};
default_random_engine ran_2 { static_cast &lt;int&gt;( chrono::high_resolution_clock::now().time_since_epoch().count())};
uniform_int_distribution &lt;int&gt; range {1,50};

a=range (ran);
b = 2;
c = 107;
d = 109;
e = 113;
f = 167;
g = 173;
h = 587;
i = 13; 

for ( k=0; k &lt; 100000; k++) {

    srand(time(NULL));
    int seed = rand();
    default_random_engine ran { static_cast &lt;int&gt;( chrono::high_resolution_clock::now().time_since_epoch().count())};
    default_random_engine ran_2 { static_cast &lt;int&gt;( chrono::high_resolution_clock::now().time_since_epoch().count())};
        uniform_int_distribution &lt;int&gt; range {1,50};
    a=range (ran);

b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;    b++;
c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;    c++;
d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;    d++;
e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;    e++;
f++;    f++;
g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;   g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;    g--;
h--;    h--;    h--;    h--;    h--;    h--;    h--;    h--;    h--;    h--;    h--;
i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;    i--;

       A= (a*b*c*f);
       B= ((A^13)/d*h-i^a);
       C= (A*B^i-b*h*g*e*a);
       D= (b+c+d+e+f+g+h+i)*a;
       E= ((a*A*B*C*D)/100000000);
       F= E % 10;
       if ( F &lt; 0 ) { G = F*(-1); } else { G = F; }

       cout &lt;&lt; G;
}
</code></pre>

<p>}</p>

<p>Thank you very much! :) Have a great day</p>
