• <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中一個元素,或者是移除一塊區域的元素)

            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  當在該list 中沒有找到要刪除的元素,那么將指向 end.


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

            #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 而是一個隨機數字
                        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;
            }
            在思考下。。。。這個問題纏繞我很久了,今天記錄下來~~~~
              

            關鍵是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;
            }
            性高朝久久久久久久久久| 国产成人久久激情91| 伊人久久大香线蕉综合网站| 日韩一区二区三区视频久久| 一本一本久久a久久综合精品蜜桃| 久久久久99精品成人片欧美| 九九久久精品国产| 午夜人妻久久久久久久久| 国产福利电影一区二区三区久久久久成人精品综合| 狠狠人妻久久久久久综合蜜桃| 国产精品久久新婚兰兰| 91麻豆精品国产91久久久久久| 久久人人爽人人爽人人片AV不 | 久久亚洲中文字幕精品有坂深雪| 99久久99久久| 亚洲中文精品久久久久久不卡| 成人a毛片久久免费播放| 久久久久免费看成人影片| 香蕉久久夜色精品国产2020| 国产精品欧美亚洲韩国日本久久 | 丰满少妇高潮惨叫久久久| 久久久久国色AV免费看图片| 久久99毛片免费观看不卡 | 浪潮AV色综合久久天堂| 久久伊人五月天论坛| 精品熟女少妇aⅴ免费久久| 热99re久久国超精品首页| 久久久久亚洲AV无码网站| 亚洲精品乱码久久久久久蜜桃图片| 日韩电影久久久被窝网| 香蕉久久永久视频| 久久久精品人妻一区二区三区蜜桃| 日日狠狠久久偷偷色综合96蜜桃| 久久99国产精一区二区三区| 99久久99久久久精品齐齐| 国产精品美女久久久| 色成年激情久久综合| 久久久无码精品午夜| 亚洲国产成人久久一区WWW| 青青久久精品国产免费看 | 久久精品国产日本波多野结衣|