小编use*_*508的帖子

二维数组的初始化数组

如何在C++中初始化二维数组的数组(在下面的代码中定义)?

#include <iostream>
#include <array>

typedef int arr3by6Int[3][6];
typedef arr3by6Int arr3xarr3by6Int[3];

void print3by6(arr3by6Int arr)
{
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 6; j++)
        {
            std::cout << arr[i][j] << " ";
        }
        std::cout << std::endl;
    }
}
int main(int argc, char const *argv[])
{

    arr3by6Int a = {
        {1,2,3,4,5,6},
        {0,0,0,0,0,0},
        {2,2,2,2,2,2}
    };

    arr3by6Int b = {
        {2,2,3,4,5,6},
        {0,0,0,0,0,0},
        {2,2,2,2,2,2}
    };

    arr3by6Int c = {
        {3,2,3,4,5,6},
        {0,0,0,0,0,0},
        {2,2,2,2,2,2}
    };

    arr3xarr3by6Int d = { …
Run Code Online (Sandbox Code Playgroud)

c++ arrays c++11

5
推荐指数
1
解决办法
1124
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1