Declaring many arrays by means of loop

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.
Why do you need that many arrays first of all?
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.
@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.
Yes that should work. Thanks.
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
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.