如何初始化数组3D在C ++中 [英] How to initialize 3D array in C++

查看:117
本文介绍了如何初始化数组3D在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C初始化数组3D ++

  INT分钟[1] [1] [1] = {100,{100,{100}}}; //这是不一样


解决方案

在你的问题中的数组只有一个元素,所以你只需要一个值完全初始化。您需要三套括号,一个用于数组的每个维度。

  INT分钟[1] [1] [1] = {{{100}}};

有一个更清晰的例子可能是:

  INT ARR [2] [3] [4] = {{{1,2,3,4},{1,2,3,4},{1,2 ,3,4}},
                     {{1,2,3,4},{1,2,3,4},{1,2,3,4}}};

正如你所看到的,有两个组,每组含有三组的4个数字。

How do you initialize a 3d array in C++

int min[1][1][1] = {100, { 100, {100}}}; //this is not the way

解决方案

The array in your question has only one element, so you only need one value to completely initialise it. You need three sets of braces, one for each dimension of the array.

int min[1][1][1] = {{{100}}};

A clearer example might be:

int arr[2][3][4] = { { {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4} },
                     { {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4} } };

As you can see, there are two groups, each containing three groups of 4 numbers.

这篇关于如何初始化数组3D在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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