固定大小向量的 C++ 向量 [英] C++ vector of fixed size vecors

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

问题描述

如何在 C++ 中声明固定大小向量的向量?

How can I declare vector of fixed size vectors in C++?

例如:

具有 N 个元素的向量.

不是这个:

vector<vector<int> > v(N) //declares vector of N vectors

推荐答案

std::array 是你的朋友.

std::array is your friend here.

http://en.cppreference.com/w/cpp/container/array

例如,要声明具有 N 个元素的向量的向量,您可以

For instance, to declare vector of vectors with N elements, you can

typedef std::array<int, N> N_array;

然后使用

std::vector<N_array>

这篇关于固定大小向量的 C++ 向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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