C++ vector > reserve size at beginning

后端 未结 4 1534
轮回少年
轮回少年 2021-01-23 21:52

in c++ I have

vector > table;

How can I resize vector so that it has 3 rows and 4 columns, all zeros?

Someth

4条回答
  •  心在旅途
    2021-01-23 22:49

    You can use resize() from std::vector :

     table.resize(4);                           // resize the columns
     for (auto &row : table) { row.resize(3); } // resize the rows
    

    Or you can directly initialize it as :

    std::vector> table(4,std::vector(3));
    

提交回复
热议问题