C++ How to dynamically create a 2D vector

前端 未结 3 2040
陌清茗
陌清茗 2021-01-27 00:14

I\'m trying to create an n x n vector that I can later cout as a table/matrix. Xcode points to the = in the for loop and tells me No

3条回答
  •  故里飘歌
    2021-01-27 01:07

    Try the following

    int n = 5;
    std::vector< std::vector > row(n);
    for (int i=0; i(n) );
    }
    

    or

    int n = 5;
    std::vector< std::vector > row(n, std::vector( n ) );
    

提交回复
热议问题