C++ 模板类vector

#include<vector>    // 包含头文件vector
...
using namespace std;    // vector包含在std中,因此必须包含std::vector

vector <int> vi;    // create a zero-size array of int

int n;
cin >> n;
vector <double> vd (n);    // create an array of n doubles
vector <double> vc_1 = {1.2, 2.3, 3.4};  // 初始化 
vector <double> vc_2 {1.2, 2.3, 3.4};  // 列表初始化 C++11新增

  vi是一个vector<int>对象,vd是一个vector<double>对象

特点:

vector对象在插入或添值时自动调整长度(使用new、delete自动管理内存)

原文地址:https://www.cnblogs.com/suui90/p/12996376.html