It is possible to specify the requested storage size of a vector during construction like this:
#include using namespace std;int main() { vector vi(1000); //initial storage for 1000 int's //vi contains 1000 elements initialized by int::int()}
Remember that vector::reserve() allocates raw memory without initializing it. The constructor, on the other hand, initializes the allocated elements by invoking their default constructor. It is possible to specify a different initializer value:
vector vi(1000, 4); //initialize all 1000 int's with 4