vector

#include <iostream>
#include <vector>
using namespace std;
int main()
{
 /*
 vector线性容器  类似于数组


 */
 vector<int>  vecInt; //不带参数
 vecInt.push_back(1);//往后面加一个
 vecInt.push_back(2);
 vecInt.push_back(3);
 int size = vecInt.size();

 vector<int> vecInt2(10);  //带参数,声明一个0到9的vector容器

 vector<int> vecInt3(5, 28);//有5个,每个是28  

 vector<int> vecInt4(vecInt3);//这样写相当于vector<int> vecInt3(5, 28);   二者相等

 vector<int> vecInt5(vecInt.begin(),vecInt.begin()+2);//这是两个迭代器  两个迭代器的取值范围是【,),并将这个
 //范围的值copy到vecInt5里面

 vecInt.resize(10);// 扩充大小,原来只有3个元素
 return 0;

}

posted @ 2017-10-27 12:10  阿蓉  阅读(179)  评论(0编辑  收藏  举报