c++中关于向量的一个问题
时间:2011-12-17
来源:互联网
我们知道向量是这样表示的:vector<int> a(10),或者vector<int> a(10,1);等等方式表示的,今天看到下面的代码还是有点不明白。
先定义了一个vector<vector<int> > a;,在.cpp中出现了“a.resize(3 ,vector<int>(5));” 这样的代码,以及“vector<vector<int> > b(a[0].size() ,vector<int>(a.size()));”这样的代码,为何在“vector<int>(5)” 这样的地方没有一个变量?这下实在没有搞懂。在此请教大侠们多指点!
先定义了一个vector<vector<int> > a;,在.cpp中出现了“a.resize(3 ,vector<int>(5));” 这样的代码,以及“vector<vector<int> > b(a[0].size() ,vector<int>(a.size()));”这样的代码,为何在“vector<int>(5)” 这样的地方没有一个变量?这下实在没有搞懂。在此请教大侠们多指点!
作者: wuleeemail 发布时间: 2011-12-17
vector(size_type __n, const value_type& __value = value_type(),
const allocator_type& __a = allocator_type())
: _Base(__n, __a)
这里后两个参数带有默认值,你可以不提供的
const allocator_type& __a = allocator_type())
: _Base(__n, __a)
这里后两个参数带有默认值,你可以不提供的
作者: qscool1987 发布时间: 2011-12-17
resize(3 ,vector<int>(5));
===
vector<int> tmp(5);
resize(3 ,tmp);
作者: mingliang1212 发布时间: 2011-12-17
引用 2 楼 mingliang1212 的回复:
resize(3 ,vector<int>(5));
===
vector<int> tmp(5);
resize(3 ,tmp);
resize(3 ,vector<int>(5));
===
vector<int> tmp(5);
resize(3 ,tmp);
不是这样的,应该是
vector<int> temp(5,0);
作者: qscool1987 发布时间: 2011-12-17
看走眼了,。。。
vector<int> temp(5,0)和vector<int> temp(5)一个意思
vector<int> temp(5,0)和vector<int> temp(5)一个意思
作者: qscool1987 发布时间: 2011-12-17
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28