Declaring many arrays by means of loop

Apr 30, 2013 at 4:29am
How could many arrays be declared by means of a loop, for example :

array1={...}; array2={...}; array3={...}; array4={...}; . . . ;array100={...};

Is it possible to make a loop in which the number at the end of the name of the array is incremented?


Thanks.
Apr 30, 2013 at 4:37am
Why do you need that many arrays first of all?
Apr 30, 2013 at 4:55am
It's a long story. I'm writing a program that minimizes chi squared with six paramaters. it would be convenient to be able to define a bunch of 6 element arrays.
Apr 30, 2013 at 4:59am
@thegege

You can't really incorporate a subscript into a variable name, the easiest thing would be to create a vector of the arrays and use the subscript to address them.

Hope all goes well.
Apr 30, 2013 at 5:03am
Yes that should work. Thanks.
Apr 30, 2013 at 5:10am
do you know why there is arrays at first place?!
To make it easier to handle huge number of the same data.
So if you want arrays of arrays of int for example you can use:
int array[10][10]
Last edited on Apr 30, 2013 at 5:10am
Apr 30, 2013 at 7:43am
There are lots of ways of storing data. One advantage of the STL containers is being able to add objects as needed. A 2d array is fine if you know the maximum size in advance.

If you are doing the same thing to all the data & don't care about the subscript, you could for example use a list of arrays or a list of vectors - and use iterators to traverse the whole container.
Topic archived. No new replies allowed.