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

 

#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

真实结果是:

posted @ 2015-03-02 15:57  陆草纯  阅读(1133)  评论(0)    收藏  举报