欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

std::remove

C++ VRCTOR中實際刪除元素使用的是容器vecrot中std::vector::erase()方。

C++ 中std::remove()并不刪除元素,因為容器的size()沒有變化,只是元素的替換。

1.std::vector::erase()

  函數原型:ITERATOR erase (iterator position);  //刪除指定元素

       iterator erase (iterator first, iterator last);  //刪除指定范圍內的元素

  返回值:指向刪除元素(或范圍)的下一個元素。(An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.)

2.代碼實例

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 
 6 int out(vector<int> &iVec)
 7 {
 8     for(int i=0;i<iVec.size();i++)
 9         cout<<iVec[i]<<ends;
10     cout<<endl;
11     return 0;
12 }
13 
14 int main()
15 {
16     vector<int> iVec;
17     vector<int>::iterator it;
18     int i;
19     for( i=0;i<10;i++)
20         iVec.push_back(i);
21 
22     cout<<"The Num(old):";out(iVec);
23     for(it=iVec.begin();it!=iVec.end();)
24     {
25         if(*it % 3 ==0)
26             it=iVec.erase(it);    //刪除元素,返回值指向已刪除元素的下一個位置    
27         else
28             ++it;    //指向下一個位置
29     }
30     cout<<"The Num(new):";out(iVec);
31     return 0;
32 }
 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 
 6 int out(vector<int> &iVec)
 7 {
 8     for(int i=0;i<iVec.size();i++)
 9         cout<<iVec[i]<<ends;
10     cout<<endl;
11     return 0;
12 }
13 
14 int main()
15 {
16     vector<int> iVec;
17     vector<int>::iterator it;
18     int i;
19     for( i=0;i<10;i++)
20         iVec.push_back(i);
21 
22     cout<<"The Num(old):";out(iVec);
23     for(it=iVec.begin();it!=iVec.end();)
24     {
25         if(*it % 3 ==0)
26             it=iVec.erase(it);    //刪除元素,返回值指向已刪除元素的下一個位置    
27         else
28             ++it;    //指向下一個位置
29     }
30     cout<<"The Num(new):";out(iVec);
31     return 0;
32 }
container.erase(remove_if(container.begin(), container.end(), pred), container.end());?

文章鏈接: http://m.qzkangyuan.com/21655.html

文章標題:std::remove

文章版權:夢飛科技所發布的內容,部分為原創文章,轉載請注明來源,網絡轉載文章如有侵權請聯系我們!

聲明:本站所有文章,如無特殊說明或標注,均為本站原創發布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發布本站內容到任何網站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
建站教程

【C++】代碼實現:運用 std::list 的 remove_if() 函數剔除數組中超出上下限的數據

2023-6-29 12:55:50

建站教程

C++設計模式:過濾器模式

2023-6-29 13:22:07

0 條回復 A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個人中心
購物車
優惠劵
今日簽到
有新私信 私信列表
搜索
主站蜘蛛池模板: 邛崃市| 江安县| 通榆县| 沙坪坝区| 竹溪县| 辽宁省| 习水县| 青浦区| 台州市| 阳春市| 息烽县| 巫溪县| 来安县| 牙克石市| 尉氏县| 从江县| 东莞市| 遂平县| 绥中县| 隆安县| 安溪县| 阿荣旗| 阿巴嘎旗| 桃园县| 嘉义县| 博罗县| 克什克腾旗| 祁连县| 壤塘县| 南乐县| 财经| 彩票| 台北县| 甘德县| 尼勒克县| 巴青县| 灌阳县| 襄汾县| 昌都县| 余江县| 广宗县|