使用 boost 分配初始化具有固定大小的向量的向量 [英] Initializing a vector of vectors having a fixed size with boost assign

查看:30
本文介绍了使用 boost 分配初始化具有固定大小的向量的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个固定大小的向量,

Having a vector of vector with a fixed size,

vector<vector<int> > v(10);

我想对其进行初始化,使其在所有元素中都有一个具有初始化值(例如 1)的一维向量.

I would like to initialize it so that it has in all elements a one dimensional vector with initialized value (for example 1).

我使用 Boost Assign 如下

I have used Boost Assign as follows

v = repeat(10,list_of(list_of(1)));

我有一个编译错误

error: no matching function for call to ‘repeat(boost::assign_detail::generic_list<int>)’

你能告诉我怎么做吗?提前致谢

Could you please tell me how to do that. Thanks in advance

推荐答案

这不使用 boost::assign 而是做你需要的:

This doesn't use boost::assign but does what you need:

vector<vector<int>> v(10, vector<int>(10,1));

这将创建一个包含 10 个 int 向量的向量,每个向量包含 10 个 int.

This creates a vector containing 10 vectors of int, each containing 10 ints.

这篇关于使用 boost 分配初始化具有固定大小的向量的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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