• <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 中沒有找到要?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;//這處同樣的問題    
                
            for (it = lst.begin(); it != lst.end(); it++)
                {
                    cout 
            << (*it) << endl;
                }
                return 
            0;
            }
            在思考下。。。。這個(gè)問題纏繞我很久了,今天記錄下來~~~~
              

            關(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;
            }
            精品免费tv久久久久久久| 国产亚洲精久久久久久无码| 亚洲午夜久久久| 久久夜色精品国产欧美乱| 国产99久久久久久免费看| 亚洲欧洲久久久精品| 久久青青草原精品影院| 亚洲欧美日韩久久精品| 亚洲天堂久久精品| 久久亚洲精品成人av无码网站| 欧美久久综合九色综合| 久久99精品久久只有精品| 久久经典免费视频| 欧美久久一级内射wwwwww.| 久久se精品一区精品二区| 久久久久久久久久久精品尤物 | 久久国产免费| 国产精品久久久久久福利漫画| 久久影视综合亚洲| 久久99精品免费一区二区| 国产精品热久久无码av| 久久久WWW免费人成精品| 久久强奷乱码老熟女| 久久中文字幕人妻丝袜| 国内精品久久久人妻中文字幕| 国产精品久久久久久久| 久久国产V一级毛多内射| 亚洲国产日韩欧美久久| 亚洲va国产va天堂va久久| 日日噜噜夜夜狠狠久久丁香五月| 777久久精品一区二区三区无码| 一本一道久久精品综合| 亚洲欧洲精品成人久久奇米网| 国内精品久久久久久久97牛牛| 亚洲国产精品久久66| 久久AV高清无码| 国产一级做a爰片久久毛片| 国产精品久久久久天天影视 | 国产精品欧美亚洲韩国日本久久| 亚洲日韩欧美一区久久久久我| 久久久久久青草大香综合精品|