How to implement 2D vector array?

后端 未结 9 705
你的背包
你的背包 2020-11-29 03:56

I\'m using the vector class in the STL library for the first time. How should I add to a specific row of the vector array?

struct x{
     vector 

        
9条回答
  •  猫巷女王i
    2020-11-29 04:28

    vector matrix(row, vector(col, 0));

    This will initialize a 2D vector of rows=row and columns = col with all initial values as 0. No need to initialize and use resize.

    Since the vector is initialized with size, you can use "[]" operator as in array to modify the vector.

    matrix[x][y] = 2;

提交回复
热议问题