0
How to write as many arrays as the user wants?
for example if cin>>n i want to create n arrays .
2 Answers
+ 3
Use a vector to store all the arrays.
#include <iostream>
#include <vector>
#include <array>
...
constexpr unsigned ArraySize = 50;
std::vector<std::array<int, ArraySize>> v;
int numberOfArrays;
std::cin >> numberOfArrays;
for( int i = 0; i < numberOfArrays; ++i )
{
v.push_back( std::array<int, ArraySize>() );
}
+ 1
or create a pointer, then allocate memory based on user input.
int *x, size;
cin>>size;
x = new int[size];