擦除后不要递增迭代器 - 这是未定义的。 for(map< int,double>: :iterator i = m.begin(); i!= m.end(); / * NO INCREMENT * /) if(i-> second< ; 0)i = m.erase(i); else ++ i; Do not increment the iterator after an erase - this is undefined.for ( map<int, double>::iterator i = m.begin(); i != m.end(); /* NOINCREMENT */ ) if ( i->second < 0 ) i = m.erase(i); else ++i; std :: map :: erase不返回迭代器(尚未)。许多当前的SL 实现可能实际上有这个,但它不应该依赖 。成语是作为擦除调用的一部分递增: if(i-> second< 0)m.erase(i ++); else ++ i; V - 请在通过电子邮件回复时删除资本''A' /> 我没有回复最热门的回复,请不要问 std::map::erase does NOT return an iterator (yet). Many current SLimplementations may actually have that, but it shouldn''t be reliedupon. The idiom is to increment as part of the call to erase: if (i->second < 0) m.erase(i++);else ++i;V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask 你必须在擦除前递增,例如 for(map< int,double> :: iterator i = m .begin(); i!= m.end();){ map< int,double> :: iterator j = i ++; if(j-> ;第二个< 0)m.erase(j); } Bernd Strieder You have to increment before erase, e.g. for ( map<int, double>::iterator i = m.begin(); i != m.end(); ) {map<int, double>::iterator j = i++;if ( j->second < 0 ) m.erase(j);} Bernd Strieder 这篇关于在地图上快速擦除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 19:16