vector push_back array
I've recently changed some code in my program from a multidimensional array to a vector, and I'm wondering if/how it's possible to initialise a vector array.
extern int LIST;
int LIST =
extern vector<int> LIST;
bool FillList(int i1, int i2, int i3, int i4, int i5)
At the moment, I use FillList() function to populate the vector. Just wondering if there's a better way to do this other than calling another function each time ?
If you also have the array, you can pass that to the vector constructor so that the vector gets initialized with the values in the array.
vector<int> list(list_array, list_array + sizeof(list_array) / sizeof(int));
Thanks for the reply!
Was a little stuck but managed to figure it out from your post.
vector<int> iVec(*iListArray,*iListArray+sizeof(iListArray) / sizeof(int));
How would one access then a particular element within vector, like you do an array given the above initialisation?
cout << iVec[i][j] doesn't work with the above particular setup?
int LIST =
cout << LIST;
Firstly, iVec would need to be either an array of vectors, or a vector of vectors (otherwise the two-dimensional syntax is invalid).
Each element of iVec would then be a vector (which can each be initialised using an approach like that described by MemLoop). You won't be able to avoid either some loop construct and/or usage of some temporary array (or vector) of ints.
When you start going to multiple dimensions with vectors, things become (literally) recursive.