首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于fflush函数,该怎么解决

2012-08-09 
关于fflush函数刚才问问题的时候有个朋友说fflush(stdin)不能保证清空stdin流,是这样吗?他说了以后我才意

关于fflush函数
刚才问问题的时候有个朋友说fflush(stdin)不能保证清空stdin流,是这样吗?他说了以后我才意识到我之前遇到的一些问题也是如此,有时候程序不会出错,但有时就执行语句以后好像总有剩余的数据,输出的东西感觉总多了什么,请问要是用什么办法能将stdin里面的全部清空能?

[解决办法]
while (fgetc(stdin) != '\n');就行了.

这是POSIX规定:

C/C++ code
NAME       fflush - flush a streamSYNOPSIS       #include <stdio.h>       int fflush(FILE *stream);DESCRIPTION       If stream points to an output stream or an update stream in which the most recent operation was not input, fflush() shall cause any unwritten  data  for       that stream to be written to the file,  and the st_ctime and st_mtime fields of the underlying file shall be marked for update.
[解决办法]
http://blog.csdn.net/csu305/article/details/3321084

热点排行