• <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中一個(gè)元素,或者是移除一塊區(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.
             我的理解是:一個(gè)雙向的迭代器指向移除元素或元素塊的 下一個(gè)存在在元素。or  當(dāng)在該list 中沒(méi)有找到要?jiǎng)h除的元素,那么將指向 end.


            如果我想在一個(gè)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 而是一個(gè)隨機(jī)數(shù)字
                        break;
                    }
                    
            else
                    {
                        it
            ++;
                    }
                }

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

            關(guān)鍵是Return 的返回。。。。。
            那么就要一個(gè) it = lst.erase(it);    此時(shí)的 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久久综合麻豆自制| 久久久久久亚洲精品影院| 久久久久国产亚洲AV麻豆| 99久久国产综合精品五月天喷水| 国产激情久久久久影院老熟女 | 久久综合久久综合亚洲| 国产成年无码久久久免费| 久久亚洲精品国产精品| 久久免费99精品国产自在现线| 要久久爱在线免费观看| 国产精品久久自在自线观看| 亚洲午夜福利精品久久| 久久发布国产伦子伦精品| 一本色道久久HEZYO无码| 精品久久久久久中文字幕人妻最新| 思思久久99热只有频精品66| 久久青青草原亚洲av无码app| 精品人妻伦一二三区久久| 潮喷大喷水系列无码久久精品 | 伊人久久国产免费观看视频 | 久久精品成人| 亚洲AV无码久久精品狠狠爱浪潮| 国产女人aaa级久久久级| 久久国产色AV免费观看| 久久久久高潮综合影院| 久久综合鬼色88久久精品综合自在自线噜噜| 婷婷久久久亚洲欧洲日产国码AV| 久久久久久国产a免费观看不卡 | 精品久久久久久国产| 久久青青国产| 久久久久女教师免费一区| 亚洲午夜精品久久久久久人妖| 日韩久久久久久中文人妻 | 2021少妇久久久久久久久久| 亚洲日韩中文无码久久| 亚洲精品无码久久久久sm| 国产成人精品综合久久久| 久久丫忘忧草产品| 日韩av无码久久精品免费| 久久久久免费精品国产|