本文介绍了vector.erase(iterator iter)将改变“iter”。或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

假设我将删除iter指向的元素。

是这样的:


vector< ints;

for(vector< int> :: iterator iter = s.begin(); iter!= s.end(); iter ++){

if(* iter == 3)

s.erase(iter); // A

}

$ A b $ b,如果元素是iter被删除后,将会删除自动指向

下一个元素(现在应该是当前元素)?

suppose I will delete an element pointed to by "iter".
like this:

vector<ints;
for(vector<int>::iterator iter=s.begin(); iter!=s.end(); iter++){
if(*iter==3)
s.erase(iter); //A
}

in line A, if element by "iter" is erased, will "iter" point to the
next element(now should be the current element) automatically?

推荐答案



引用已删除元素的所有元素以及删除后的所有元素

都被该操作无效。 IOW,

标准版没有尝试定义被删除后''iter''指向

的内容。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回应top-发表回复,请不要问

The iterator that refers to the removed element and all elements
after the removed one are invalidated by that operation. IOW, the
Standard makes no attempt to define what the ''iter'' would point to
after being erased.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask




Do:


vector< ints;

for(vector< int> :: iterator iter = s.begin(); iter!= s.end(); iter ++){

if(* iter == 3)

iter = s.erase (iter);

}

Do :

vector<ints;
for(vector<int>::iterator iter=s.begin(); iter!=s.end(); iter++){
if(*iter==3)
iter= s.erase(iter);
}




这是什么?

将s.erase() ;删除3后的所有元素?

What''s this?
will "s.erase()" get all the elements after "3" removed?


这篇关于vector.erase(iterator iter)将改变“iter”。或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:04