C++ 模板类vector
时间:2020-05-31 10:06:03
收藏:0
阅读:59
#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
评论(0)