vector

#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;
}
原文地址:https://www.cnblogs.com/13224ACMer/p/5806616.html