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二维数组模板输出方法 先写个记录,有空再整理发上来
随机推荐
- apache 配置会话保持
1.修改apache_home/conf/httpd.conf,增加以下模块(取消注释,如有其他依赖, 则相应取消注释) LoadModule proxy_module modules/mod_pro ...
- SpringMVC -- 梗概--源码--贰--mvc:annotation-driven
1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Handler和执行Handler 2>如果配置了<mv ...
- 记安装ubuntu server和一些程序
1. 安装ubuntu server 按照流程走了一遍,一切画面都正常,就是重启后界面只有一个光标闪啊闪,我不知道应该再装一遍还是找老大来解决,想了下,以前电脑就是因为出错才重装的,现在这个情况有可能 ...
- 通过SSH实现Windows与linux之间传输文件
Linux是非常好的开发环境,但很多时候我们希望能够在Windows上操作,通过SSH协议可以实现两者之间传输文件. 一 需要在Linux系统上安装ssh-server,有的linux系统自带了. 查 ...
- 【Android】水平居中 垂直居中 中心居中
android:layout_centerInParent 将该组件放置于水平方向中央及垂直中央的位置 android:layout_centerHorizontal 将该组件放置于水平方向中央的位置 ...
- iOS开发--提交应用Your binary is not optimized for iPhone 5
ERROR ITMS-: "Your binary is not optimized for iPhone 5 - New iPhone apps and app updates submi ...
- java.security.NoSuchAlgorithmException: SHA1PRNG SecureRandom not available
好久没有使用MyEclipse10了,今天打开看了以前大学的项目,在Tomcat7中发布启动,我嚓嘞,报错: SEVERE: Exception initializing random number ...
- python 学习笔记---文件处理
1.打开文件读取数据 f =open(“wenjian.txt”,"r") print(f) f.close() 直接变成列表--->list(f) for each_lin ...
- JS 实现拖动效果
<html> <body style="margin:0px;"> <script src="http://ajax.googleapis. ...
- x64免签名驱动程序
DSEFix GitHub https://github.com/hfiref0x/DSEFix