Possible Duplicate:
STL remove doesn’t work as expected?
Sorry, I'm new to C++11 and iterators. This is supposed to remove all the number 3's in the array, but it doesn't remove the last one. Why?
#include <algorithm>
#include <array>
#include <iostream>
int main() {
std::array<int, 8> a{{9, 3, 4, 5, 33, 5, 6, 3}};
int N(3);
std::remove(a.begin(), a.end(), N);
for (int i : a) {
std::cout << i << '\n';
}
}
I get as output:
{ 9, 4, 5, 33, 5, 6, 6, 3 }
^
|
// the last 3 is still there