首页 > 编程语言 > 详细

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

时间:2015-03-02 16:30:40      阅读:225      评论:0      收藏:0      [点我收藏+]

 

#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

原文:http://www.cnblogs.com/ganganloveu/p/4308984.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!