vector容器
#include <iostream>
#include <vector>using namespace std;
void printVector(vector<int> &v)
{//定义一个迭代器 ==指针vector<int>::iterator iter;//v.end()是最后一个元素的下一个元素地址for(iter=v.begin();iter!=v.end();iter++){cout << *iter << " ";}cout << endl;
}int main()
{vector<int> v;v.push_back(12); //尾插v.push_back(25);v.push_back(31);v.push_back(49);v.push_back(51);//遍历printVector(v);vector<int> v2=v;printVector(v2);vector<int> v3(v2.begin()+2,v2.end());printVector(v3);vector<int> v4(6,88);printVector(v4);return 0;
}
运行结果