|
To:superandy
This may not be just the keyboard.
K&R's "The C Programming Language" said:
Appendix B1.1:
On an output stream, fflush causes any buffered but unwritten data to be written; on an input stream, the effect is undefined.
Of course, it is mentioned in the C language standard.
C99 7.19.5.2
(2) If stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined.
I understand it this way: Although for a general keyboard and its driving mode, clearing the buffer area of a keyboard, its meaning is completely understandable.
But C / C ++ 's "standard input stream" does not necessarily point to a normal keyboard, and can also be redirected.
For example, if stdin is redirected to a file, wouldn't it make sense to "flush" a file input? Do you want to discard all the data read into memory? Or discard it by line? What about binary files? |
|