"cin"未命名类型


#include <iostream>
#include <string.h>
using namespace std;
/* Variables */
int N = 0;
int M = 0;
int Px, Py;
int gcount = 0;
cin >> N >> M;
string maze[100];
/* Define Functions */
void read_maze(int);
void scan_maze(int);
void print_maze();

这是我正在制作的一个基于文本的游戏的代码片段,当我运行它时,我会收到以下错误:

main.cpp:10:1: error: 'cin' does not name a type
10 | cin >> N >> M;
| ^~~

我无法调试代码的问题。有什么想法吗?

编辑:Atom

操作系统:Windows 10

编译器:MinGW

感谢

必须在函数内部使用语句,例如

#include <iostream>
int main() {
/* Variables are fine at global scope, but you should prefer local ones */
int N = 0;
int M = 0;
int Px, Py;
int gcount = 0;

/* Here's the problematic statement from before */
std::cin >> N >> M;
...
}

最新更新