2012-02-17 94 views
2

可能重复:
C/C++: Capture characters from standard input without waiting for enter to be pressed如何连续读取标准输入?

有没有办法读取标准输入不断?我想制作一个X和O游戏,我希望玩家使用箭头移动它在网格上的位置。我无法使用cin,因为它要求您按Enter键以将输入数据转换为变量。那么,这样做的功能或对象是否存在?

+2

没有平台无关的方法。 – 2012-02-17 08:10:15

+1

这解释了如何在Windows和Linux的控制台应用程序中执行此操作: http://stackoverflow.com/questions/421860/cc-capture-characters-from-standard-input-without-waiting-for-enter -to-be-pr – termie 2012-02-17 08:19:04

回答

3

对于控制台(文本)应用程序,你会使用像ncurses这样的终端'GUI'控件。

对于图形应用程序,您可以使用类似SDL这样的事件驱动编程。

+0

非常感谢! – user1215706 2012-02-18 06:45:22