I think you are confusing a vector's
capacity
with its
size
.
std::vector<t>.capacity() is the number of elements the vector can hold based on the current memory allocation. Whether that is the same thing as the
capacity
that is shown here is not clear.
If you know that you have a large number of items, say 10,000 or 1,000,000 to add to the vector, you can pre-allocate using one of the vector constructors:
std::vector<int> arr(1000000);
Note that this does not affect the size of
arr
, it will still be zero, but when adding elements to the array, the first 1,000,000 items will have already been allocated.