初始化二维向量< int>在CPP [英] Initialize a 2 Dimensional vector<int> in CPP

查看:392
本文介绍了初始化二维向量< int>在CPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C ++中初始化二维向量< int>

How to initialize a 2 dimensional vector<int> in C++?

每个长度为8个int,如下所示

For instance I have 4 arrays each of length 8 ints, like the below

int a1[] = {1,2,3,4,5,6,7,8};
int a2[] = {1,2,3,4,9,10,11,12};
int a3[] = {1,2,5,6,9,10,13,14};
int a4[] = {1,3,5,7,9,11,13,15};

我有这个

vector< vector <int> > aa (4);

aa[i] (a1,a1+8);

但这会产生错误。我甚至试过提供数组a1到v1,并传递v1到 aa [i] ,仍然失败。

But this gives error. I even tried supplying the array a1 to v1 and passed v1 to aa[i] , still it fails.

那么,什么是初始化二维向量的元素的正确方法

So what would be the proper way of initializing the elements of a 2 dimensional vector<int>

推荐答案

aa[i].assign(a1,a1+8);

这篇关于初始化二维向量&lt; int&gt;在CPP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆