How do I put prime numbers into a vector?
<p>I have written a piece of code below, that asks for a user input and checks whether it is prime or not. I want to build on this now, so when the user inputs a number, I count the number of primes up to this number and display. For example, if the user enters 10, my program will output 'there are 4 primes'. My thinking is that I have to store each prime number into a vector, but my question is how?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;vector&gt;
using namespace std;

int main()
{
    vector &lt;double&gt; primeHolder
    int x, i, flag;
    cout &lt;&lt; "Enter a positive integer ";
    cin &gt;&gt; x;

    for (i = 2; i &lt;= x/2; i++)
    {
        if(x%i == 0)
        {
            flag = 1;
            break;
        }
    }

    if (flag == 0)
        cout &lt;&lt; "This is a prime number";
    else
        cout &lt;&lt; "This is not a prime number";
    return 0;
}
</code></pre>