转自:http://blog.csdn.net/kuaile123/article/details/11105115

vector::erase误使用问题:

  暂时使用经验: 不能在循环中使用,否则会报如题错误。

2014/03/11更新:循环删除容器中符合条件的元素

  《C++ Primer(Edit 5)》, P.349

  Both forms of erase return an iterator referring to the location after the(last) element that was removed.That is, if j is the element following i, then erase(i) will return an iterator referring to j.

  Example:

    list<int> lst = {0,1,2,3,4,5,6,7,8,9}

    auto it = lst.begin();

    while (it != lst.end())

    {

      if (*it % 2)

        it = lst.erase(it);

      else

        ++it;

    }

[转]vector iterator not incrementable 的问题的更多相关文章

  1. vector iterator not incrementable For information on how your program can cause an an assertion Failure, see the Visual c + + documentation on asserts

    #include <list> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<int> sl ...

  2. C++ error C2440: “类型转换” : 无法从“std::vector::iterator”转换为“

    原文地址:http://blog.csdn.net/onlyou930/article/details/5602654 圆环套圆环之迭代器 话说这一日是风平浪静,万里乌云,俺的心情好的没得说,收到命令 ...

  3. 迭代器类vector::iterator 和 vector::reverse_iterator 的实现、迭代器类型、常用的容器成员

    一.迭代器 迭代器是泛型指针 普通指针可以指向内存中的一个地址 迭代器可以指向容器中的一个位置 STL的每一个容器类模版中,都定义了一组对应的迭代器类.使用迭代器,算法函数可以访问容器中指定位置的元素 ...

  4. STL.vector.iterator的序号

    ZC:网上查到,使用vector时,只要将 find到的iterator(itX)减去vector::begin() 就可以得到itX的序号. 1.需求:得到 某个 iterator在 vector中 ...

  5. ERROR: iterator not incrementable || iterator not decrementable

    这个错误提示:迭代器不可以增加 exmaple: vector<int> tVecInt; vector<int>::reverse_iterator iterInt = tV ...

  6. map set iterator not incrementable 解决办法

    例子: #include <iostream> #include <map> using namespace std; int main() { map<int, int ...

  7. STL vector容器需要警惕的一些坑

    从迭代器中取值切记需要判断是否为空 例如: vector<int> vtTest; vtTest.clear(); if (vtTest.empty()){ ; } ]; 如果没有忘了判断 ...

  8. C++中如何在顺序容器中删除符合特定条件的元素

    以前很少做删除操作,vector一直当成数组用,而实际追求效率时又经常舍弃vector选用C风格数组.看<C++ Primer>到顺序容器删除这节时试着实现课后习题结果一动手我就出错了. ...

  9. Vector和Stack(已过时,不建议使用)

    以下内容基于jdk1.7.0_79源码: 什么是Vector和Stack Vector:线程安全的动态数组 Stack:继承Vector,基于动态数组实现的一个线程安全的栈: Vector和Stack ...

随机推荐

  1. 【英语】Bingo口语笔记(55) - work系列

  2. HDFS命令行文件操作

    Hadoop文件操作命令形式为 hadoop fs -cmd <args> 说明:cmd是具体的文件操作命令,<args>是一组数目可变的参数. Hadoop最常用的文件操作命 ...

  3. perl环境配置以及Eclipse安装perl开发插件

    简介: 这篇文章将详细介绍 EPIC 组件的安装,EPIC 编辑环境,调试运行环境,着重介绍如何使用 EPIC 来快速.简便.准确地调试 Perl 语言程序,包括对于 Perl 程序的单步执行,断点用 ...

  4. arcgis9.3 执行python文件

    1) 打开Python GUI 2) 选择菜单“File->Open”,打开你要执行的*.py文件 3) 选择菜单“Run->Run Module”,运行python文件 4)运行结果

  5. [教程] Windows Server 2008 R2架设SMTP服务器发送邮件教程

    Windows Server 2008 R2 架设SMTP服务器实现邮件发送 目的:架设SMTP服务器实现邮件发送. 一.域名设置 添加“邮件交换记录(MX)”: Newjs.cn           ...

  6. Delphi Val函数

    在这里Val和iif都是你所用的数据库中的函数在delphi中Val是一个将字符串转换为数字的函数,Val(S; var V; var Code: Integer)第一个参数是要转换的字符串,第二个参 ...

  7. IOS AutoLayout 遍历修改约束

    self.cvv2View.hidden = YES; self.periodView.hidden = YES; [self.contentView.constraints enumerateObj ...

  8. org.unsaved transient instance - save the transient instance before flushing: bug解决方案

    最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下: 1.遇如下bug: org.unsaved transient instance - save the transient instan ...

  9. 【C#】如何创建xml文件以及xml文件的增、改

    增: using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpre ...

  10. Objective-C开发图书推荐

    日本Objective-C圣经级教材:Objective-C编程全解(第3版) 作      者 [日] 荻原刚志 著:唐璐,翟俊杰 译 出 版 社 人民邮电出版社 出版时间 2015-01-01 版 ...