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

std::remove

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

C++ 中std::remove()并不刪除元素,因?yàn)槿萜鞯膕ize()沒有變化,只是元素的替換。

1.std::vector::erase()

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

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

  返回值:指向刪除元素(或范圍)的下一個(gè)元素。(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.代碼實(shí)例

 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);    //刪除元素,返回值指向已刪除元素的下一個(gè)位置    
27         else
28             ++it;    //指向下一個(gè)位置
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);    //刪除元素,返回值指向已刪除元素的下一個(gè)位置    
27         else
28             ++it;    //指向下一個(gè)位置
29     }
30     cout<<"The Num(new):";out(iVec);
31     return 0;
32 }
container.erase(remove_if(container.begin(), container.end(), pred), container.end());?

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

文章標(biāo)題:std::remove

文章版權(quán):夢(mèng)飛科技所發(fā)布的內(nèi)容,部分為原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明來源,網(wǎng)絡(luò)轉(zhuǎn)載文章如有侵權(quán)請(qǐng)聯(lián)系我們!

聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個(gè)人或組織,在未征得本站同意時(shí),禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺(tái)。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。

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

【C++】代碼實(shí)現(xiàn):運(yùn)用 std::list 的 remove_if() 函數(shù)剔除數(shù)組中超出上下限的數(shù)據(jù)

2023-6-29 12:55:50

建站教程

C++設(shè)計(jì)模式:過濾器模式

2023-6-29 13:22:07

0 條回復(fù) A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個(gè)人中心
購(gòu)物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索
主站蜘蛛池模板: 白沙| 筠连县| 军事| 陇川县| 长治县| 长乐市| 雷州市| 曲松县| 海口市| 苏尼特右旗| 收藏| 阿城市| 合江县| 英山县| 个旧市| 昭通市| 东乡县| 托克逊县| 沙洋县| 遂溪县| 綦江县| 普洱| 西藏| 墨玉县| 清镇市| 府谷县| 嘉峪关市| 玛沁县| 新沂市| 庆元县| 郯城县| 莱芜市| 边坝县| 金门县| 阳西县| 隆林| 巴青县| 秦皇岛市| 安庆市| 凤山县| 皮山县|