c++arraysvector

storing n numbers of vectors in array


I have n numbers of vectors, that gets generated based upon the user input. I want to store them in an array or vectors.

I am coming from PHP, and in PHP you can store arrays inside another array. How can I achieve this in C++. by storing n number vectors inside an array, or inside a vector.

This is somehow how it can be achieved in PHP, assuming PHP has vectors

    for (int i = 0 ; i< userInput ; i++)
     {
         arrayOfVectors[] =  vector<string> students_1;

      }

Solution

  • The easiest thing would be to use a vector of vectors:

    std::vector<std::vector<string>> data (userInput);
    

    That creates a vector with userInputs vectors of string. How you use this depends on your requirements, which aren't clear from the question, a least not to someone unfamiliar with PHP.