Is there a 2D vector like a 2D array

2d array table for LCS - C ++, vector

I've written code to solve the Longest Common sequel problem. Only the 2D table with the dimensions of m X w needs to be defined. I had defined it as a global variable, but it threw an over-capacity error.

I am considering using the vector of the vector, but then it is possible to define the size as m x w at the same time. A normal

would not be enough as I would like to define the vectors beforehand and access them using the index operator like in the code.


1 for the answer № 1

Yes, it is possible as long as all inner vectors are the same size.

The first argument is this (How many objects should be in the first) and the second argument is the value that will be used to initialize each of these values. In the above case, you get 9000 vectors, each filled with 9000 times the number 23.

A full list of constructors is here.

3 for the answer № 2

To use

to generate a vector of magnitude.

This works because of the two parameters std :: vector constructor:

what takes the size as the first parameter and value as the second parameter so there are copies of, that is, copies of the size (with default values, that is 0).


2 for the answer № 3