Initial capacity of vector in C++

The standard doesn’t specify what the initial capacity of a container should be, so you’re relying on the implementation. A common implementation will start the capacity at zero, but there’s no guarantee. On the other hand there’s no way to better your strategy of std::vector<int> iv; iv.reserve(2345); so stick with it.

Leave a Comment