vector是一个向量容器,可以容纳多种类型。
初始化:
其中要包含头文件#include<vector>
vector<T> a;//T是类型名,可以自定义类型
二、遍历
1、可以和数组一样直接循环访问。
2、也可以使用迭代器访问
vector<int>::iterator a1;
for (a1 = a.begin(); a1 != a.end(); a1 += 1)
{
cout << *a1 << endl;
}
//其中a.end()是指向末尾元素后面一个的地址,不可以访问。
3、简化版(忘了叫啥了)
for(auto it:a)
{
cout<<it<<endl;
}
//it是自己起的遍历容器的一个名字。a是vector<int>a;
以上是个人知道内容,有遗漏请补充。