c++ - 如何在使用 2d 数组作为参数时创建 3d 数组

标签 c++ arrays

    int main()
    {
      cout << "Welcome to the Maze Game!\n";
      cout << "(press ENTER to start)";
      cin.get();
      system("cls"); 
      bool maze[ROWS][COLS];
      loadMaze(maze);

      bool map[ROWS][COLS] = {};
      int 
        x = 0, 
        y = 0;

      map[y][x] = 1;

     printMap(map, x, y);

函数定义

我如何定义以便将 map 用作参数。

void printMap(bool array[][ROWS][COLS])
{    
        // DECIDE BETWEEN:
        // print '.' if the user has been at spot before
        // print 'x' character (NOT the value of variable x) to MARK the user's current position
        // print '#' for spots the user has NOT been yet

}

最佳答案

你可以通过map进入printMap作为:

void printMap(bool map [ROWS][COLS])

void printMap(bool map [][COLS])

如果您想从 2D 制作 3D 阵列 map , 您可以在 printMap 中定义一个新的 3D 数组并使用来自 map 的数据.但是,我强烈建议您使用 std::vector而不是原始数组,因为它们更易于使用。有兴趣者,here是关于 std::vector 的一些文档.

关于c++ - 如何在使用 2d 数组作为参数时创建 3d 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51460942/

相关文章:

c - 奇怪的数组错误 C

javascript - 按浮点值对数组进行排序

c - 如何读取 C 中以空格分隔的 0-9 数字?

c++ - undefined reference C++

c++ - 丢失和再次找到时的对象跟踪

C:函数未返回正确的值

javascript - 按特定字母对 JS 字符串数组进行排序

c++ - 如何在不使用真正的剪贴板的情况下进行类似剪贴板的操作?

c++ - 在 Linux 上使用 X11 抓取特定键上的事件

c++ - 计数器的问题