0

How to write as many arrays as the user wants?

for example if cin>>n i want to create n arrays .

17th Oct 2018, 8:21 AM
Vikram
Vikram - avatar
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>() ); }
17th Oct 2018, 8:44 AM
Dennis
Dennis - avatar
+ 1
or create a pointer, then allocate memory based on user input. int *x, size; cin>>size; x = new int[size];
17th Oct 2018, 11:42 AM
Taste
Taste - avatar