getch() 函数在输入 key 时不执行任何操作
getch() function does nothing when entering key
getch(( 函数什么都不做,我的程序卡在 getch(( 行!
我想使用 getch(( 在 c++ 中获取 char 输入,但是当我运行这段代码时没有任何反应,即使我输入了一些东西,它也卡在 char c= getch(( 中。
#include <iostream>
#include <graphics.h>
#include <conio.h>
using namespace std;
int main()
{
int n = 4;
int table[10][10] = {{0}};
srand(time(NULL));
table[0][rand() % n] = 2;
table[n - 1][rand() % n] = 2;
cout << 1;
char c = getch();
cout << c;
}
我的项目是一个图形项目,但我的代码中没有initwindow(lentgh,width)
。所以我在循环之前将此命令添加到我的代码中,然后重试(在图形窗口打开时按我的键(。然后,它奏效了!我不知道原因,但这就是我问题的答案。
相关文章:
- 我在执行任何程序时被拒绝在 devcpp 中访问
- 不执行任何操作的函数调用C++
- 如果普通默认构造函数不执行任何操作,为什么我们不能使用 malloc 创建平凡可构造的对象?
- GDI+-无法对Gdiplus::Graphics(C++)执行任何操作
- 当我将 DLL 注入现有进程时,DLLMain 不执行任何操作
- 调用函数来创建 WinAPI 按钮不会执行任何操作
- 发送到另一个窗口的鼠标移动消息不执行任何操作
- 如果默认构造函数不执行任何操作,则目的是什么
- 尝试执行任何需要它的操作时,无法修复 WinAPI 中的"invalid handle"错误
- 程序在运行时不执行任何操作
- 调用向量内的函数指针不执行任何操作
- getch() 函数在输入 key 时不执行任何操作
- 在集合上运行的函数模板,该集合具有默认的"transform"函数,该函数不执行任何操作
- 重复Handle()是否执行任何解释性通信(IPC),如果不是为什么目标参数
- 基于 Visual Studio c++ 的 exe 不执行任何操作
- C/C++ 套接字:如果我在 IPv6 TCP 连接之前执行任何操作,则连接将失败
- 在执行任何程序代码之前,通过静态 .lib 链接到 dll 的程序会发生什么情况
- 使用 for 循环反转数组不执行任何操作
- C++功能运算符结构不执行任何操作
- 如何创建不执行任何操作的 #define