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 = newdouble[x]
}
To sum up my question is: can you create/name an array using a variable in c++?
// 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[].