用C整数的三维阵列++ [英] Three dimensional arrays of integers in C++
本文介绍了用C整数的三维阵列++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找出落实在C ++中的整数的三维阵列,使用指针算术/动态内存分配,或交替使用 STL
技术,如安全的方法向量。
I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using pointer arithmetic / dynamic memory allocation, or, alternatively using STL
techniques such as vectors.
基本上我想我整数数组尺寸如下:
Essentially I want my integer array dimensions to look like:
[ x ][ y ][ z ]
x和y的范围20-6000
z被公知和等于4。
x and y are in the range 20-6000 z is known and equals 4.
推荐答案
看一看升压多维数组库。这里有一个例子(改编自Boost文档):
Have a look at the Boost multi-dimensional array library. Here's an example (adapted from the Boost documentation):
#include "boost/multi_array.hpp"
int main() {
// Create a 3D array that is 20 x 30 x 4
int x = 20;
int y = 30;
int z = 4;
typedef boost::multi_array<int, 3> array_type;
typedef array_type::index index;
array_type my_array(boost::extents[x][y][z]);
// Assign values to the elements
int values = 0;
for (index i = 0; i != x; ++i) {
for (index j = 0; j != y; ++j) {
for (index k = 0; k != z; ++k) {
my_array[i][j][k] = values++;
}
}
}
}
这篇关于用C整数的三维阵列++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文