首页 > 代码库 > vector容器总结.xml
vector容器总结.xml
<style
type="text/css">
pre{
line-height:1;
color:#800080;
background-color:#d2c39b;
font-size:16px;}.sysFunc{color:#627cf6;font-style:italic;font-weight:bold;}
.selfFuc{color:#0ed896;}
.bool{color:#d2576f;}
.condition{color:#000080;font-weight:bold;}
.key{color:#000080;}
.var{color:#008080;font-style:italic;}
.Digit{color:#ff00ff;font-weight:bold;}
.includePre{color:#800080;}
.operator?{color:#a776df;font-weight:bold;}
</style>
1?清空所有元素
????m_itemVector.clear();??
2?遍历
????vector<ITEM_CHECK>::iterator?iter=m_itemVector.begin();?? ????for(i=0;iter!=m_itemVector.end();iter++,i++)?? ????{?? ????????if(iter->flag==-1)?? ????????{?? ????????????break;?? ????????}?? ????????iter->flag=1;?? ????}??
????vector<ITEM_CHECK>::iterator?iter=m_itemVector.begin();?? ????for(i=0;iter!=m_itemVector.end();iter++,i++)??//先全部取消?? ????{?? ????????iter->flag=0;?? ????}??
3?删除符合条件的项
????int?CurrentCount=(int)m_itemVector.size();?? ????for(int?i=0;i<CurrentCount;i++)?? ????{?? ????????if(m_itemVector.at(i).flag==1)?? ????????{?? ????????????m_itemVector.erase(m_itemVector.begin()+i);?? ????????????DeleteItem(i);?? ????????????this->Invalidate();???? ?????? ????????????CurrentCount--;?? ????????????i--;????????????????????????//删除第i位置后,需要重新判断第i位置是否符合条件,因此需要i--。?? ????????}?? ????}??
4??正序遍历?然后反序遍历
????vector<ITEM_CHECK>::iterator?iter=m_itemVector.begin();?? ????for(i=0;iter!=m_itemVector.end();iter++,i++)??//先全部取消?? ????{?? ????????iter->flag=0;?? ????}?? ?????? ????for?(;i>0;)???????????????????????//从后往前设置??iter?退到Begin()?再减的话?就会出现问题?? ????{?? ?????? ????????iter--;??//结束时,正好退到Begin()?? ????????i--;?? ????????iter->flag=1;?? ????}??
5?在VECTOR中查找
????#include<vector>?? ????#include<algorithm>??//在VECTOR中查找?? ????using?namespace?std;??
????vector<int>?L;?? ????L.push_back(?1?);?? ????L.push_back(?2?);?? ????L.push_back(?3?);?? ????L.push_back(?4?);?? ????L.push_back(?5?);?? ????vector<int>::iterator?result?=?find(?L.begin(?),?L.end(?),?3?);?//查找3?? ????if?(?result?==?L.end(?)?)?//没找到?? ????????cout?<<?"No"?<<?endl;?? ????else?//找到?? ????????cout?<<?"Yes"?<<?endl;??
本文使用?书画小说软件?发布,内容与软件无关,书画小说软件?更惬意的读、更舒心的写、更轻松的发布。
vector容器总结.xml
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。