• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            在MSDN中: Standard C++ Library Reference 
            list::erase 

            Removes an element or a range of elements in a list from specified positions.(從指定的位置,移除list中一個元素,或者是移除一塊區(qū)域的元素)

            Return Value:
                        A bidirectional iterator that designates the first element remaining beyond any elements removed, or a pointer to the end of the list if no such element exists.
             我的理解是:一個雙向的迭代器指向移除元素或元素塊的 下一個存在在元素。or  當(dāng)在該list 中沒有找到要刪除的元素,那么將指向 end.


            如果我想在一個list中保存 1---10,然后查找并且 刪除5 的代碼 應(yīng)該是

            #include <iostream>
            #include 
            <list>
            using namespace std;

            list
            <int> lst;
            int main()
            {
                
            for (int i = 0; i < 10; i++)
                {
                    lst.push_back(
            10-i);
                }

                list
            <int>::iterator it = lst.begin();
                
            for (; it != lst.end();)
                {
                    
            if((*it) == 5)
                    {
                        cout 
            << "Find It" << endl;
                        cout 
            << (*it) << endl;
                        lst.erase(it);
                        cout 
            << (*it) << endl;//這不是我想要的4 而是一個隨機(jī)數(shù)字
                        break;
                    }
                    
            else
                    {
                        it
            ++;
                    }
                }

                it 
            = lst.begin();
                lst.erase(it);
                     cout 
            << (*it) << endl;//這處同樣的問題    
                
            for (it = lst.begin(); it != lst.end(); it++)
                {
                    cout 
            << (*it) << endl;
                }
                return 
            0;
            }
            在思考下。。。。這個問題纏繞我很久了,今天記錄下來~~~~
              

            關(guān)鍵是Return 的返回。。。。。
            那么就要一個 it = lst.erase(it);    此時的 it 才是我要要的,也是Return 所描述的。。。
            代碼 如下:

            #include <iostream>
            #include 
            <list>
            #include 
            <vector>
            using namespace std;

            list
            <int> lst;
            vector
            <int> vec;
            int main()
            {
                
            for (int i = 0; i < 10; i++)
                {
                    lst.push_back(
            10-i);
                    vec.push_back(i);
                }

                list
            <int>::iterator it = lst.begin();
                
            for (; it != lst.end();)
                {
                    
            if((*it) == 5)
                    {
                        cout 
            << "Find It" << endl;
                        cout 
            << (*it) << endl;
                        it 
            = lst.erase(it);//注意要接受返回的值
                        cout 
            << (*it) << endl;
                        break;
                    }
                    
            else
                    {
                        it
            ++;
                    }
                }
                vector
            <int>::iterator it2 = vec.begin();

                
            for (; it2 != vec.end(); it2++)
                {
                    
            if((*it2) == 5)
                    {
                        cout 
            << "Find it in vector" << endl;
                        cout 
            << *it2 << endl;
                        it2 
            = vec.erase(it2);//注意要接受返回的值
                        cout 
            << *it2 << endl;
                    }
                }

                it 
            = lst.begin();
                it 
            = lst.erase(it);  //注意要接受返回的值
                cout 
            << (*it) << endl;

                
            for (it = lst.begin(); it != lst.end(); it++)
                {
                    cout 
            << (*it) << endl;
                }
                return 
            0;
            }
            97久久超碰成人精品网站| 无码8090精品久久一区| 久久人人妻人人爽人人爽| 久久影院综合精品| 久久久久免费视频| 人妻无码中文久久久久专区| 93精91精品国产综合久久香蕉| 久久国产视频99电影| 人妻少妇久久中文字幕| 久久国产精品国语对白| 无码人妻精品一区二区三区久久| 伊人久久综在合线亚洲2019 | 久久久精品一区二区三区| 超级碰久久免费公开视频| 色综合久久夜色精品国产| 热久久这里只有精品| 伊人久久大香线蕉综合Av| 久久精品一区二区三区中文字幕| 久久精品人人槡人妻人人玩AV| 无码国内精品久久人妻麻豆按摩| 99久久综合狠狠综合久久| 色诱久久久久综合网ywww| 伊人热热久久原色播放www| 一本伊大人香蕉久久网手机| 日韩AV无码久久一区二区| 色欲综合久久躁天天躁| 久久久久99精品成人片三人毛片| 国产麻豆精品久久一二三| 久久午夜伦鲁片免费无码| 精品国产乱码久久久久久呢| 伊人久久亚洲综合影院| 少妇被又大又粗又爽毛片久久黑人| 99久久婷婷国产综合精品草原| 日本一区精品久久久久影院| 丰满少妇人妻久久久久久| 婷婷综合久久中文字幕蜜桃三电影| 久久天天婷婷五月俺也去 | 国内精品综合久久久40p| 亚洲性久久久影院| AV无码久久久久不卡蜜桃| 2021国内精品久久久久久影院|