Jerry's Blog

Recording what I learned everyday

View on GitHub


4 January 2021

cpp -- Templates, Vectors, and Stacks(2)

by Jerry Zhang

The C++ vector Class

声明一个vector:

vector<int> intVector;
vector<string> stringVector;
vector<int> intVector(10);

访问vector的某个值,也可以用方括号.

vector的size()函数返回的是一个unsigned int。所以遍历时也可以这样写:

for (unsigned i = 0; i < intVector.size(); i++)
tags: cpp