c++ - '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;
| ^~~
我无法用代码调试问题。有任何想法吗?
编辑:原子
操作系统: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;
...
}
推荐阅读
- python-3.x - 为什么生产者在我的示例中几乎完全重新获取条件线程?
- r - 如何让 document() 接受 µ
- javascript - Nodejs:正则表达式不返回任何内容
- tableau-api - 如何设置非连续日期过滤器?
- c++ - C ++:如何使用其参数之一对从类派生的对象向量进行排序
- python - python input() 在调用 input() 之前采用旧的标准输入
- reporting-services - 如何删除以“和”SSRS 2016 表达式结尾的行上的最后 3 个字符?
- postgresql - 如何避免 Postgres 中的静态查询?
- java - Recursively finding words in a hashmap using tries
- r - 通过匹配所有可能的行和列的键来添加任何缺失的行和列