Я работал над книгой Страуструпа: https://rads.stackoverflow.com/amzn/click/com/0321543726 В настоящее время я работаю над упражнением 13 главы 4, в котором вам предлагается реализовать алгоритм решета Эратосфена для нахождения простых чисел между 1 и 100. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Сейчас я пытаясь удалить числа, кратные 2. Я пробовал как функцию стирания, так и remove_if (что вызывает нечетные ошибки сегментации). Я не ищу советов по реализации, просто помогите с удалением элементов векторов.
#include "std_lib_facilities.h"
#include <math.h>
#include <vector>
/*
This program attempts to find the prime numbers in the range of a value
using the Sieve of Eratosthenes algorithm.
*/
int main() {
vector<int>primer;
cout<<"This program calculates prime numbers up until a value max\n"
"and prints these out."<<endl;
int max = 100;
for (int i = 2; i <= max; i += 1) { //creates a list of integers from 2 to 100.
primer.push_back(i);
}
for (int n = 2; n < max; n += 2) { //attempts to delete the multiplies of 2, excluding 2 itself.
primer.erase(?);
}
copy(primer.begin(), primer.end(), ostream_iterator<int>(cout, " "));//prints the elements of the vector
}
Любая помощь приветствуется! Спасибо!