I've changed the initial array to include 0 and 1 to match the positions of the vector up.
Thanks for the help anon, here is the finished code:
Code:
vector<int> primes;
int n, numToCheck;
cout << "Please enter n: ";
cin >> n;
//populate num list
for(int i = 0; i < n; i++)
{
primes.push_back(i);
}
//move through array, eliminating multiples
for(int i = 0; i < primes.size(); i++)
{
numToCheck = primes[i];
//dont check already marked
if(numToCheck > 1)
{
//removes multiples
for(int j = numToCheck; j < primes.size(); j += numToCheck)
{
//check we aren't removing the prime
if(j == i)
continue;
primes[j] = 0;
}
}
}
primes.erase(std::remove(primes.begin(), primes.end(), 0), primes.end());
for(int i = 0; i < primes.size(); i++)
{
cout << primes[i] << endl;
}