关于getch() [英] about getch()

查看:60
本文介绍了关于getch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想按任意键继续在Windows中,我可以使用getch()

但getch()不是标准的C函数

那么我应该在Linux中做些什么呢?

If I want to "press any key to continue" in Windows, I can use getch()
But the getch() isn''t a standard C function
So what should I to do in Linux?

推荐答案

fuzhen写道:
fuzhen wrote:

如果我想按任意键继续在Windows中,我可以使用getch()

但是getch()不是标准的C函数

那么我应该在Linux中做些什么呢?
If I want to "press any key to continue" in Windows, I can use getch()
But the getch() isn''t a standard C function
So what should I to do in Linux?



"按下您要按下的键以外的任何键。


"按ENTER键也是候选人。


-

Eric Sosman
es ***** @ ieee-dot-org.inva 盖子


6月12日上午8:56,fuzhen < fuc ... @ gmail.comwrote:
On Jun 12, 8:56 am, fuzhen <fuc...@gmail.comwrote:

如果我想按任意键继续在Windows中,我可以使用getch()

但是getch()不是标准的C函数

那么我应该在Linux中做些什么呢?
If I want to "press any key to continue" in Windows, I can use getch()
But the getch() isn''t a standard C function
So what should I to do in Linux?



getch()是一个非标准的扩展,它不会回显输入的字符

。在标准C中,您可以使用getchar(),getc(),fgetc()....

所有这些函数都读取一个字符。在Windows中,常见的做法

是使用getch()来暂停程序。 conio.h和getch()

都是非标准扩展。为了更安全,你可以随时使用getchar()来编写可移植代码。

getch() is a non-standard extension which does not echo the character
entered. In standard C, you can use getchar(), getc(), fgetc() ....
All these functions read a character. In Windows, the common practice
is to use getch() for halting the program. Both conio.h and getch()
are non-standard extensions. To be on the safer side, you can always
use getchar() if you are trying to write portable code.


fuzhen写道:
fuzhen wrote:

如果我想按任意键继续在Windows中,我可以使用

getch()
If I want to "press any key to continue" in Windows, I can use
getch()



为什么要这样做?


只需从shell / dos窗口运行你的程序,并避免凌乱

函数,这些函数会使代码混乱,并将其渲染到无用的批处理脚本上。

。 />

-

彼得

Why would you want to do that?

Just run your program from a shell/dos window and avoid messy
functions that just clutter your code and render it next to useless
for batch scripts.

--
Peter


这篇关于关于getch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆