0

Lets say I have this below.

int arrays = 0;

cin >> arrays ;

for(int i = 0; i < arrays ; i++)
{
        ????? Not sure what to do here.
}

And I want to create x number of arrays the user entered with 39 elements(40). How would I create this forloop to create 4 arrays? for example it would make array1 array2 array3 array4

7
  • 2
    I dont know how to try this Commented Dec 28, 2012 at 8:38
  • 1
    Try creating vector of vectors instead: std::vector<std::vector<int> > vec; (also #include <vector>) check here for an example Commented Dec 28, 2012 at 8:38
  • int array [39]; But how can i get them each a different name? Commented Dec 28, 2012 at 8:38
  • I want arrays for this . Commented Dec 28, 2012 at 8:42
  • Vectors achieve a very similar thing. Must you use arrays? Have you been told to use arrays? Commented Dec 28, 2012 at 8:44

1 Answer 1

2
int arrays = 0;

cin >> arrays ;

int *ptr = new int [arrays]; //Make sure to validate arrays against errors
                             //and don't forget to de-allocate using delete[] when done

for(int i = 0; i < arrays ; i++)
{
        ptr[i] = i;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.