3

I have problem with initializing the following vector:

int main()
{
    ...
    int size = classData.size();
    vector<vector<string>> arrayClass[size][3];     // <-- problem
    for(int i = 0 ; i < classData.size(); i++)
    {
        for(int j = 0 ; j < 3; j++)
        {
            arrayClass[i][j] = classData[j+i];
        }
    }
}

It says that size must be constant value. Any thoughts?

1
  • You have a 2D array of 2D vectors of strings, which are like a vector. 5 dimensions is not going to go well when trying to use it. Commented Nov 11, 2013 at 17:57

1 Answer 1

8
vector<vector<string>> arrayClass[size][3];

was meant to be:

vector<vector<string>> arrayClass(size, vector<string>(3));

which takes advantage od std::vector's constructor, which initializes the vector with appropriate size, filling it with empty strings.

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.