首页 > 其他 > 详细

vector

时间:2016-08-25 14:30:39      阅读:298      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


int main(){

    vector<int >vv(5,123);

    vector<int >::iterator ite=vv.begin();
    
    while(ite!=vv.end()){
        cout<<*ite<<endl;
        ++ite;
    }

    cout<<vv.size()<<"  "<<vv.capacity()<<endl;
    int a=5;
    vv.push_back(a+a);
    cout<<vv.size()<<"  "<<vv.capacity()<<endl;
    
    int& tmp=vv.front();
    cout<<tmp<<endl;
    tmp=vv.back();
    cout<<tmp<<endl;

    cout<<"-------------"<<endl;
    vv.pop_back();

    cout<<vv.size()<<"  "<<vv.capacity()<<endl;

    cout<<"+++++++++++++++"<<endl;


    vector<int>::iterator itepos=::find(vv.begin(),vv.end(),123);


    itepos=vv.erase(itepos);


    //vv.insert(itepos,2,333);
    
     ite=vv.begin();
    
    while(ite!=vv.end()){
        cout<<*ite<<endl;
        ++ite;
    }

    cout<<"++++++++++++++"<<endl;
    vv.clear();


    return 0;
}

 

vector

原文:http://www.cnblogs.com/13224ACMer/p/5806616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!