How to implement 2D vector array?

I’m not exactly sure what the problem is, as your example code has several errors and doesn’t really make it clear what you’re trying to do. But here’s how you add to a specific row of a 2D vector:

// declare 2D vector
vector< vector<int> > myVector;
// make new row (arbitrary example)
vector<int> myRow(1,5);
myVector.push_back(myRow);
// add element to row
myVector[0].push_back(1);

Does this answer your question? If not, could you try to be more specific as to what you are having trouble with?

Leave a Comment