编程日志5.20
vector基础概念
柔性数组(可以动性扩缩容),底层数据结构
范围区间左闭右开 扩容 申请内存空间
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a[6] = {9, 8, 7, 6, 5, 4};
// 扩容
vector<int> v = {2, 0, 2, 4};
// 正常情况下,std::vector<int> 有capacity成员函数,这里可以正常输出容量
cout << v.capacity() << endl;
v.push_back(7);
cout << v.capacity() << endl;
//左闭右开
cout << "begin->"<< *v.begin() << endl; //begin指向这个数的指针
cout << "end->"<< *(v.end()-1) << endl;
cout << "front->"<< v.front() << endl; //front这个值
cout << "back->"<< v.back() << endl;
return 0;
}
/*
vector<double> v;
vector<char> v;
vector<vector<int>> v;
vector<vector<vector<int>>> v;
*/