有没有办法在标准C ++中直接从键盘读取输入? [英] Is there a way to read input directly from the keyboard in standard C++?
本文介绍了有没有办法在标准C ++中直接从键盘读取输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有 std :: cin
,但这需要用户输入一个字符串,然后按ENTER键。有没有办法简单地得到推送的下一个键而不需要按ENTER确认
And I know there's std::cin
, but that requires the user to enter a string, then press ENTER. Is there a way to simply get the next key that is pushed without needing to press ENTER to confirm
推荐答案
p>
You can use
#include <conio.h>
,然后使用
char c;
if (_kbhit())
{
c = getch();
switch(c)
{
case ‘\0H’ :
cout << "up arrow key!" << endl;
break;
}
}
注意:没有尝试过...并记得把整个事情放到一个while(true)来测试。
Beware: I have not tried it... and remember to put the whole thing into a "while(true)" to test.
这篇关于有没有办法在标准C ++中直接从键盘读取输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文