c++中用vector创建多维数组的初始化方法
最近调试一个程序,在使用vector声明一个二维数组时出现错误。错误的方法如下所示:
std::vector<std::vector<double> > sphereGrid;
int gridLA = angleSpanLA / angelAccuracy;
int gridLO = angleSpanLO / angelAccuracy;
sphereGrid = std::vector<std::vector<double> >( gridLA , gridLO );
会出现如下报错:
/home/zn/VanishingPointDetection/src/VPDetection.cpp: In member function ‘void VPDetection::getSphereGrids(std::vector<std::vector<double> >&)’:
/home/zn/VanishingPointDetection/src/VPDetection.cpp::: error: no matching function for call to ‘std::vector<std::vector<double> >::vector(int&, int&)’
sphereGrid = std::vector<std::vector<double> >( gridLA , gridLO );
这就是因为二维数组的初始化出现了错误,一般的话要通过下面这种方式初始化
定义空二维vector,再赋值
vector<vector <int> > ivec(m ,vector<int>(n)); //m*n的二维vector,注意两个 "> "之间要有空格!
所以我们要把程序改为
std::vector<std::vector<double> > sphereGrid;
int gridLA = angleSpanLA / angelAccuracy;
int gridLO = angleSpanLO / angelAccuracy;
sphereGrid = std::vector<std::vector<double> >( gridLA , std::vector<double>(gridLO) );
就可以解决错误,通过这次改错更加认识到了c++之vector的用法。
参考:https://blog.csdn.net/ldkcumt/article/details/51396980
https://blog.csdn.net/oNever_say_love/article/details/50763238
c++中用vector创建多维数组的初始化方法的更多相关文章
- c++用vector创建二维数组
1 vector二维数组的创建和初始化 std::vector <int> vec(10,90); //将10个一维动态数组初始为90std::vector<std::vector& ...
- stl vector创建二维数组
vector<vector<); for (auto it = v.begin(); it != v.end(); it++) { ; (*it).reserve();//预留空间为5,但 ...
- vector创建2维数组
以前我要建立一个二维数组,总是使用 int N=5, M=6; vector<vector<int> > Matrix(N); for(int i =0; i< Matr ...
- C语言 动态创建二维数组
/*C语言 如何动态创建二维数组 转化为一维数组申请数组,创建和释放都比较简单 */ #include <stdlib.h> #include <stdio.h> #inclu ...
- Python创建二维数组(关于list的一个小坑)
0.目录 1.遇到的问题 2.创建二维数组的办法 3.1 直接创建法 3.2 列表生成式法 3.3 使用模块numpy创建 1.遇到的问题 今天写Python代码的时候遇到了一个大坑,差点就耽误我交作 ...
- c/c++ 图的创建(二维数组法)
c/c++ 图的创建(二维数组法) 图的概念 图由点和线组成 知道了图中有多少个点,和哪些点之间有线,就可以把一张图描绘出来 点之间的线,分有方向和无方向 创建图 创建图,实际就是创建出节点,和节点之 ...
- C#中创建二维数组,使用[][]和[,]的区别
C#中,我们在创建二维数组的时候,一般使用arr[][]的形式,例如 int[][] aInt = new int[2][]; 但声明二维数组还有一种方法,是使用arr[,]的形式.两者有什么区别呢? ...
- Java使用Array类创建多维数组
1.创建一维数组 import java.lang.reflect.Array; public class ArrayTest { public static void main(String[] a ...
- thinkphp二维数组模板输出方法
thinkphp二维数组模板输出方法 先写个记录,有空再整理发上来
随机推荐
- ASP.NET用DataSet导出到Excel
//读取临时文件 GYYW.DA.Common.Base_SqlDataBase daBZDM = new GYYW.DA.Common.Base_SqlDataBase(); DataS ...
- JQuery Mobile 简单入门引导
看了慕课网的jqm视频(http://www.imooc.com/learn/207),觉的不错,简单截几个图,做一下备忘:
- POJ1159——Palindrome
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 53647 Accepted: 18522 Desc ...
- 大杂烩 -- Java中Iterator的fast-fail分析
基础大杂烩 -- 目录 Java中的Iterator非常方便地为所有的数据源提供了一个统一的数据读取(删除)的接口,但是新手通常在使用的时候容易报如下错误ConcurrentModificationE ...
- ios开发之--理解NSStringDrawingOptions每个选项的用法与意义
typedef NS_OPTIONS(NSInteger, NSStringDrawingOptions) { NSStringDrawingUsesLineFragmentOrigin = < ...
- [Git] 解决 insufficient permission for adding an object to repository database
[环境] OS: CentOS 6.5 Git: 1.7.1 [症状描述] Git 中心仓库路径 ~/project.git,克隆库路径 ~/project.clone,克隆库中包含一个文件 ~/pr ...
- iOS 动画效果:Core Animation & Facebook's pop
本文转载至 http://www.cocoachina.com/ios/20151223/14739.html 感谢原创作者分享 前言相信很多人对实现 iOS 中的动画效果都特别头疼,往往懒得动手,功 ...
- x64枚举DPC定时器
@写在前面 不同于x86,x64的DPC是被加密了的.对于x64DPC的兴趣始于我已经流产的scalpel计划.当时问某牛怎么遍历,得到的答案是“500大洋给代码”.真是R了狗了,好歹小哥我 ...
- Android开发训练之第五章第四节——Syncing to the Cloud
Syncing to the Cloud GET STARTED DEPENDENCIES AND PREREQUISITES Android 2.2 (API level 8) and higher ...
- Python3.6的组件numpy的安装
安装numpy,scipy,scikit-learn,matplotlib 下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/ 我的版本是win10+py ...