Dynamically create array named after for loop iterator

Hey so I want to create n arrays (based off user input) of size x (also off user input). The way I was thinking of doing it was having a for loop perform n iterations and inside the loop ask the user for x. The problem is I'm not sure how to name the array using the variable n, I was thinking something like:
1
2
3
4
5
6
7
8
9
10
11
cout << "Enter n: ";
cin >> n

for (i = 0; i < n; i++)
{
    cout << "Enter x: ";
    cin >> x;

    double*array+i;
    array+i = new double[x]
}

To sum up my question is: can you create/name an array using a variable in c++?

Thanks in advance for the help, much appreciated.

~Henry
You want to make an array of arrays. The easiest (and safest) way to do this is to use vectors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

// a vector of a vector = an array of arrays
//   but vectors are also resizable
std::vector<  std::vector<double> > arrays;

cout << "Enter n: ";
cin >> n;

arrays.resize(n); // create n arrays

for(int i = 0; i < n; ++i)
{
    cin >> x;

    arrays[i].resize(x);  // resize arrays[i] to be x units big
}


// you can then access elements with

arrays[ a ][ b ]  // where 'a' is which array you want, and 'b' is which element in that array 



If you cannot use vectors, the equivilent would be a "nested new" approach, you you allocate an array of pointers with new[], then allocate arrays for each of those pointers with another new[].
Wow that is very useful, thanks so much.
Topic archived. No new replies allowed.