I would like to use vector or list (or anything like that) as a multidimentional array, is it possible ? If so, how can I do that ?
For example, how can I change the following code into "something similar" but use vector/list/...
Originally posted by Charleston
I would like to use vector or list (or anything like that) as a multidimentional array, is it possible ? If so, how can I do that ?
For example, how can I change the following code into "something similar" but use vector/list/...
Thanks Paul very much,
But I still have another question that, I do not know how to use that array a, if it is declared as what you have taught me, would you please spend some time explaining a little more ??
Thank You,
But since I have just been taught about using vector of vector of string, I would like to use push_back and even some std functions like transform, I dont know how I can make it now
If it is just a normal 1d vector I can try to handle it, but now it gets doubled (vector<vector>),I am stuck,
I can do as what Paul told me but I would like to know a little more, would anyone help me ?
Originally posted by Andreas Masur
In general, a basic understanding of the 'vector' class should help...take a look at the following introduction...
Thank Andreas a lot, I didnot pay attention to that link, I didnot know there is one out there,
But I think Philip's post is great and specific especially to the example I gave out, it may be a cake to many gurus like Andreas, but to a newb like me, it is not at all, and I like his solutions, True !
Philip,
I would like to ask for another favor,
Philip gave me that solution but it is just for matrix 2xN, how about MxN matrix,I donot know how to do that, would Philip be nice to help me again ???
Originally posted by jlou
Philip's code works fine for MxN matrices. In his example, M just happens to be 2 because he only pushed back twice.
You could use a for loop to initialize each entry to a specific value:
Code:
const int M = 26;
const int N = 38;
I2 v;
for (i=0; i<M; ++i)
{
I1 va;
for (j=0; j<N; ++j)
{
va.push_back(i);
}
v.push_back(va);
}
or if you can initialize them all to the same value then:
Code:
const int M = 26;
const int N = 38;
// Initialize all to 17.
I2 v(M, I1(N, 17));
// Initialize all to 0.
I2 v2(M, I1(N));
Thanks jlou a lot, I was trying to make it work, but I couldnot, I didnot understand his code could work for NxM matrix,
Thanks jlou a lot, you helped me out...
Bookmarks