之前看<C++ Primier>的时候,也解到在顺序型窗口里insert/erase会涉及到迭代器失效的问题,并没有深究.今天写程序的时候遇到了这个问题. 1 莫名其妙的Erase 最初我的程序是酱紫的,别说话,我知道这样是有问题的,可这样是最直观的想法 int arr[]={0,1,2,3,4,5,6,7,8,9,10}; vector<int> a(arr,arr+sizeof(arr)/sizeof(*arr));for (auto it = a.begin(); it !=…
Advance(i, n) increments the iterator i by the distance n. If n > it it , the call has no effect. advance(i, n)使得迭代器i增加一个长度n.如果n>,那么advance(i, n)等价于执行++i操作n次,如果n<,那么等价于执行- -i操作n次,如果n=,那么这个调用没有任何影响. Defined in the standard header iterator, and in…