Two methods that may interest you:
Fragment Example
std::vector<int> v; for (int i =0; i < 25; ++i) v.push_back (i); v.reserve (100); std::cerr << "Elements: " << v.size () << std::endl; std::cerr << "Capacity: " << v.capacity () << std::endl;
Output
Elements: 25 Capacity: 100
I assume that your sample fragment in the original message contains at least one typo, you do not declare std::vector<int> elements with N , writing below.
What you wrote will be that the data is an array of vector<int> size N , and it would compile if N were known at compile time (or if your compiler had a variable length extension).
vector<int> data[N];
To create vector and insert N elements from the very beginning:
std::vector<int> data (N);
source share