请问我想用fflush函数把标准输入stdin,输入到文件text中该怎么做?
by bj1234567890 - C/C++ - 2009-08-25 16:19:16 阅读(1310) 回复(3)
同样一个程序:
#include
想实验下printf的缓冲,于是写了下面一小段代码
#include
为测试输入缓冲清空,代码test.c如下:
#include
Remarks The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams opened for output. The stream re...
如下代码,把fflush注释掉,为何结果一样。[code]#include
As we known that fflush(3) is a standard C library function. So it should be has the same behavior on any platforms which support standard ansi C library. But when I wrote fflush(stdin); Windows will discard all things stored in the system's standard input buffer. So when I issue getchar(3) next fflush(3), I could get correct character I wish. FreeBSD, contrasted with windows, has not the effe...