是否可以根据键盘输入退出 C++ 循环,而无需每次迭代都实际输入一些内容?
例如
while(checkkeyboardinput != 'q')
{
do work
}
我觉得这很容易,但谷歌没有帮助我,我不记得如何做到这一点。感谢您的帮助。
编辑:我正在使用 VS2008
最佳答案
试试 _kbhit()。据我所知,它会检查缓冲区中是否有任何键盘输入在等待。
http://msdn.microsoft.com/en-us/library/58w7c94c%28VS.80%29.aspx
_kbhit
Checks the console for keyboard input.
int _kbhit( void );
Return Value
_kbhit returns a nonzero value if a key has been pressed. Otherwise, it returns 0.
Remarks
The _kbhit function checks the console for a recent keystroke. If the function returns a nonzero value, a keystroke is waiting in the buffer. The program can then call _getch or _getche to get the keystroke.
关于c++基于键盘输入的退出循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/695960/