初始化二维 vector,为 m*n 的vector,所有值为 0.
- 直接用初始化方法
vector<vector<int>> test(m, vector<int>(n, 0));
- 用resize()来控制大小
vector<vector<int>> test; test.resize(m);//m行 for (int k = 0; k < m; ++k) { res[k].resize(n);//每行为c列 }
vector<vector<int>> test(m, vector<int>(n, 0));
vector<vector<int>> test;
test.resize(m);//m行
for (int k = 0; k < m; ++k) {
res[k].resize(n);//每行为c列
}