如何以可移植的方式验证ANSI C中的stdin缓冲区中是否有一些信息? [英] How to verify if there is some information in the stdin buffer in ANSI C in a portable way?

查看:24
本文介绍了如何以可移植的方式验证ANSI C中的stdin缓冲区中是否有一些信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ANSI C 中开发一个可移植的函数,以验证 stdin 缓冲区是否为空.这个想法是用它来验证用户是否按下了某个键.

I'm trying to develop a portable function in ANSI C that verifies if the stdin buffer is empty. The idea is to use it to verify if the user has pressed some key.

在 Windows 中,使用 kbhit(来自 conio.h)很容易做到这一点,但它依赖于操作系统.

In windows, it is easy to do that using kbhit (from conio.h), but it is OS dependent.

不过,我想开发自己的便携功能.

However, I'd like to develop my own portable function.

推荐答案

ANSI C 和当前的 C 标准都没有提供执行此操作的方法.它只能使用特定于实现的扩展来完成.

Neither ANSI C nor the current C standard provides a way to do this. It can only be done using implementation-specific extensions.

这篇关于如何以可移植的方式验证ANSI C中的stdin缓冲区中是否有一些信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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