Thank goodness for websites like this one....
I've been out of the C++ loop for about 10 yrs - so many changes (and things I've forgotten).
It seems that the new "vector" type may be what I want.
I need to declare a 4 dimensional array (user specified length and to be read from file). So far, I'd like to be able to use the vector functions for manipulating and storing.
Assuming numx, numy, mx and my represent the dimensions for f I need to figure out how to make the syntax work for the addition line which I know is incorrect. Below is the basic idea (using the standard namespace here...):
void my_func(int numx, int numy, int mx, int my,
vector< vector< vector< int > > > & f){
for(i=0;i<mx;i+ +)
for (j=0; j<my;j++)
for(k=0;k<numx; k++)
for(m=0;m<numy; m++)
f[i][j][k][m] = i + j + k + m;
}
Also, I know when declaring
vector<int> v(5);
will create 5 elements in the vector.
In this case is it possible to declare all 4 of the dims at the same time??
And then take this a step further initialize them as well like you would when doing
vector<int> v(5,1);
to initialize all 5 elements to the value of 1?
Your help is most greatly appreciated.
I've been out of the C++ loop for about 10 yrs - so many changes (and things I've forgotten).
It seems that the new "vector" type may be what I want.
I need to declare a 4 dimensional array (user specified length and to be read from file). So far, I'd like to be able to use the vector functions for manipulating and storing.
Assuming numx, numy, mx and my represent the dimensions for f I need to figure out how to make the syntax work for the addition line which I know is incorrect. Below is the basic idea (using the standard namespace here...):
void my_func(int numx, int numy, int mx, int my,
vector< vector< vector< int > > > & f){
for(i=0;i<mx;i+ +)
for (j=0; j<my;j++)
for(k=0;k<numx; k++)
for(m=0;m<numy; m++)
f[i][j][k][m] = i + j + k + m;
}
Also, I know when declaring
vector<int> v(5);
will create 5 elements in the vector.
In this case is it possible to declare all 4 of the dims at the same time??
And then take this a step further initialize them as well like you would when doing
vector<int> v(5,1);
to initialize all 5 elements to the value of 1?
Your help is most greatly appreciated.
Comment