C++容器vector

#include <vector>
using std::vector;

1.定义和初始化

vector<int> i1;    //int的对象
vector<Sales_item> i2;    //Sales_item的对象
vector<vector<string>> file;  //该向量的元素是vector对象,有时需要在在最后两个>中间加一个空格

初始化:
vector<T> v1;   空的
vector<T> v2(v1); v2中包含所有v1的元素
vector<T> v2 = v1; 同上
vector<T> v3(5,23); 有5个元素,每个元素的值都是23
vector<T> v4{5,6,7,8,9}; 有5个元素,已赋值
vector<T> v5(10); 10个元素,默认初始化

猜你喜欢

转载自www.cnblogs.com/penuel/p/11691030.html