If you work with large vectors (size > 100000100,000) and want to delete lots of elements, I would recommend to do something like this:
int main(int argc, char** argv) { vector <int> vec; vector <int> vec2; for (int i = 0; i < 20000000; i++){ vec.push_back(i);} for (int i = 0; i < vec.size(); i++) { if(vec.at(i) %3 != 0) vec2.push_back(i); } vec=vec2; vec = vec2; cout << vec.size() << endl; } The code takes every number in vec, that can't be divided by 3 and copies it to vec2. Afterwards it copies vec2 inin vec. It It is pretty fast. To proceedprocess 20.,000.,000 elements this algorithm only takes 0.8 sec!
I did the same thing with the erase-method, and it takes lots and lots of time:
Erase-Version (10k elements) : 0.04 sec Erase-Version (100k elements) : 0.6 sec Erase-Version (1000k elements): 56 sec Erase-Version (10000k elements): ...still calculating (>30min>30 min)