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

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

问题描述

你如何在 C++ 中初始化一个 3d 数组

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} } };

如您所见,有两组,每组包含三组,每组 4 个数字.

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

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

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