【stl学习笔记】vector

vector是定义于namespace std内的template:

namespace std
{
    template<class T, class Allocator = allocator<T>>
    class vector;
}

vector优异性能的秘诀之一,就是配置比其所容纳的元素所需更多的内存。capacity()函数返回vector实际能够容纳的元素数量。如果超越这个数量,vector就要重新配置内部存储器。

vector的容量之所以重要,是因为:

1.一旦内存重新配置,和vector元素相关的所有references,pointers,iterators都会失效

2.内存重新配置很耗时间

vector的迭代器相关函数

c.begin()

c.end()

c.rbegin()

c.rend()

原文地址:https://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3870459.html