c++ - 如何在使用 2d 数组作为参数的同时创建 3d 数组
问题描述
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);
功能定义
我如何定义以便将地图用作参数。
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
,你可以定义一个新的 3D 数组printMap
并使用来自map
. 但是,我强烈建议您使用std::vector
原始数组而不是原始数组,因为它们更容易使用。如果你有兴趣,这里有一些关于std::vector
.
推荐阅读
- angular - Angular/cli 不会在 Dart-Sass 中运行我的 ng serve 并出现错误
- flutter - Flutter 相当于 Sencha 的 NestedList?
- android - 如何在存储库中初始化 okHttp 的 MockServer()?
- dart - 以阿拉伯语格式显示数字 Dart
- pyomo - 从 IPOPT 求解器获取:CPU 时间、#iterations 、目标函数的值并将它们保存在 Pyomo 上的向量中
- mongodb - Mongodb按字符串数组排序并使用索引
- git - 如何将我的分支继承的基本提交移动为当前分支中的第一个提交?
- python - FileNotFoundError:[Errno 2] 没有这样的文件或目录:'/home/ubicomp/ubicomp/questions_check'。(将文件放入 SFTP 服务器。)
- git - 如何在 SourceTree 中禁止空提交?
- android - 如何删除工具栏中的设置?