zoukankan      html  css  js  c++  java
  • 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> slist;
        list<int>::iterator iter;
            slist.push_back(1);
            slist.push_back(5);
        slist.push_back(11);
        for(iter = slist.begin(); iter != slist.end(); ++iter)
        {
            if(11 == *iter)
                slist.erase(iter);
        }
        return 0;
    } 
    
    

    问题(vector iterator not incrementable For information on how your program can cause an an assertion Failure, see the Visual c + + documentation on asserts. (Press Retry to debug the application)
    这个比较典型,当删除的元素不是最后一个,则没有太大问题。
    VS2008下运行这个,当slist.erase(iter);当要删除的元素是slist中的最后一个的时候,执行erase之后
    iter就指向end了,再次进入for循环,执行++iter就出错了。。。(erase会是迭代器失效)

    默认的是const  iterator  是会出现这种错误的:

    判断

    if (it != m_Bullsts.end())   //迭代器失效
    {
    it++;
    }

  • 相关阅读:
    [AGC020E] Encoding Subsets
    [Topcoder16346]TwoPerLine
    CF913E Logical Expression
    英语面试
    CRM
    WEB使用第三方支付服务大致流程
    OO语言 prototype 初级用法
    flash设置字体
    air 提示问题
    c#里的BYTE
  • 原文地址:https://www.cnblogs.com/locojyw/p/3843506.html
Copyright © 2011-2022 走看看