【发布时间】:2013-10-31 14:23:24
【问题描述】:
我想了好几次这个问题,但我总是忘记问。那么如何编写一个 C/C++ 例程来检查我按下了什么键,以便在按下键后立即返回结果?如何在 Windows 中实现这一点?如何在 Linux 中实现这一点?如果我使用 Dev-C++ 和 Code::Blocks 应该包含哪些标题?
我试试这个:
#include <iostream>
#include <conio.h>
int main(void)
{
using namespace std ;
cout << "Press a key" << endl ;
char key ;
getch() >> key ;
cout << "\nYou have pressed: " << key << endl ;
return 0 ;
}
但它没有告诉我我按下了什么键。如何获取键值?
【问题讨论】:
-
How to accomplish that in Windows ? How to accomplish that in Linux ? What headers I should include if I use Dev-C++ and Code::Blocks ?一个问题有这么多问题? -
code:blocks 是一个 ide
-
如果这个问题太多了,那我只需要知道如何在windows和C++代码中的Dev-C++中完成它
-
我们是在谈论控制台还是基于窗口的程序?
-
我在控制台程序中需要这个