This simple code for some reason works perfectly fine on my desktop but when I try it on my laptop only the first part (printing the elements of vector) works then the program ends and instead of saying "Process finished with exit code 0" it says
"Process finished with exit code -1073741819 (0xC0000005)". I don't know what's wrong with my laptop. Can anyone help me?
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> array{1, 2, 3, 4, 5};
vector<int>::iterator it;
int arraysize;
for (int i = 0; i < array.size(); i++) {
cout << array[i] << endl;
}
cout << " " << endl;
for (it = array.begin(); it < array.end(); it++) {
if(*it%2==0){
array.erase(it);
it--;
}
}
arraysize=array.size();
cout<<"size:"<<arraysize<<endl;
for (int i = 0; i < array.size(); i++) {
cout << array[i] << endl;
}
return 0;
}