这是我写的一段C++代码:
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v = {1, 2, 3, 4, 3, 2, 1};
int main(){
v.erase(remove(v.begin() + 3, v.begin() + 6,3), v.end());
for(int c : v) printf("%d ",c);
return 0;
}
我认为他应该在(下标从0开始) [3,6] 即 v3∼v6 这一段区间中删除一个 3,并输出
1 2 3 4 2 1
可是实际上只输出了
1 2 3 4 2
这是为什么?