How can I declare vector of fixed size vectors in C++?
For example:
vector of vectors with N elements.
Not this:
vector<vector<int> > v(N) //declares vector of N vectors
std::array is your friend here.
http://en.cppreference.com/w/cpp/container/array
For instance, to declare vector of vectors with N elements, you can
typedef std::array<int, N> N_array;
Then use
std::vector<N_array>
You could use std::array:
std::array<int, 10> myNumbers;
The only down side to this is you can't see how many "active" elements there are, since you don't push/emplace back. You use it like an ordinary( but safe ) array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With