问题描述
屏幕快照显示了NetBeans IDE上C ++中的一堆变量声明,每个变量声明都有错误“找不到其声明的标识符”。
我已经查看了有关该主题的其他文章,似乎对其他人有用的解决方案也无济于事。这可能很简单(例如在某处缺少符号),或者我做错了。我目前正在学习C ++,我在Java和Python与NetBean上都做得很好,没问题。但是我在使用此代码时遇到了很多错误。
这是下面的示例代码。 (尚未完成,但不确定为什么到目前为止每一行都出现此错误)
#include <cstdlib>
#include <cctype>
#include <vector>
#include <iostream>
using namespace std;
/*
*
*/
int main() {
int mazeMap[4][4] = {
{32,34,3,32,34}
{13,13,12,14,13}
{1,24,14}
{3,234,34}
{12,124,4,3}
};
int downorRight = 32;
int downorLeft = 34;
int downOnly = 3;
int downorUp = 13;
int UpOrRight = 12;
int leftOrUp = 14;
int upOnly = 1;
int leftOrRight = 24;
int downorLeftOrRight = 234;
int leftOrDownorRight = 124;
int leftOnly = 4;
char northDir = 'w';
char eastDir = 'd';
char southDir = 's';
char westDir = 'a';
cout << "Welcome to the Marble Maze" << endl;
while (userInp != 'q') {
}
return 0;
}
解决方法
我不使用netbeans,但是代码存在一些问题。
迷宫贴图数组太小。您需要将其尺寸设置为[5][5]
,以获取给定的值。另外,初始化列表之间也需要逗号:
int mazeMap[5][5] = {
{32,34,3,32,34},{13,13,12,14,13},{1,24,14},{3,234,{12,124,4,3}
};
未声明变量userInp
。
同时运行该程序将以无限循环结束。因此,您可能想为用户输入添加代码。