Three dimensional arrays of integers in C++ -
i find out safe ways of implementing 3 dimensional arrays of integers in c++, using pointer arithmetic / dynamic memory allocation, or, alternatively using stl
techniques such vectors.
essentially want integer array dimensions like:
[ x ][ y ][ z ]
x , y in range 20-6000 z known , equals 4.
have @ boost multi-dimensional array library. here's example (adapted boost documentation):
#include "boost/multi_array.hpp" int main() { // create 3d array 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 elements int values = 0; (index = 0; != x; ++i) { (index j = 0; j != y; ++j) { (index k = 0; k != z; ++k) { my_array[i][j][k] = values++; } } } }
Comments
Post a Comment