#include <iostream>     // std::cout
#include <vector>       // std::vector
using namespace std;

int main () {

    vector<vector<int> > theta;
    theta.resize(1, vector<int>(2, 1));
    theta.resize(2, vector<int>(3, 2));
    for(int i = 0; i < theta.size(); i ++)
    {
        for(int j = 0; j < theta[i].size(); j ++)
            cout << theta[i][j] << " ";
        cout << endl;
    }
  return 0;
}

本来目的是让第二次resize覆盖掉第一次的resize,得到2行3列的2

真实结果是:

【C++】不要想当然使用resize

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2021-08-15
  • 2021-09-01
  • 2021-10-24
  • 2022-02-22
  • 2021-10-18
  • 2022-01-07
相关资源
相似解决方案