• <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;
            }
            美女写真久久影院| 亚洲国产精品无码久久SM| 国产精品久久永久免费| 久久国产精品-久久精品| 亚洲狠狠婷婷综合久久蜜芽| 久久婷婷国产综合精品| 亚洲成人精品久久| 思思久久99热只有频精品66| 欧美一区二区三区久久综合 | 国产99久久九九精品无码| 污污内射久久一区二区欧美日韩| 亚洲精品无码成人片久久| 国内精品久久久久久久久电影网 | 精品久久久无码人妻中文字幕豆芽| 高清免费久久午夜精品| 久久久一本精品99久久精品88| AV无码久久久久不卡网站下载| 午夜精品久久久久久影视777| 国产∨亚洲V天堂无码久久久| 99久久国产亚洲综合精品| 国产—久久香蕉国产线看观看 | 蜜臀久久99精品久久久久久小说| 91久久精品国产成人久久| 久久w5ww成w人免费| 青青草原综合久久大伊人| 亚洲&#228;v永久无码精品天堂久久 | 青青热久久国产久精品| 99久久综合国产精品二区| 久久精品夜夜夜夜夜久久| 热久久视久久精品18| 三级片免费观看久久| 久久精品亚洲精品国产欧美| 天天久久狠狠色综合| 久久久久四虎国产精品| 久久97精品久久久久久久不卡| 久久精品夜夜夜夜夜久久| 久久亚洲精品中文字幕| 婷婷伊人久久大香线蕉AV| 久久久久亚洲AV成人片| 国产精品久久久久AV福利动漫| 色诱久久久久综合网ywww|