I am not able to flush stdin

后端 未结 7 1787
孤城傲影
孤城傲影 2020-11-22 14:51

How to flush the stdin??

Why is it not working in the following code snippet?

#include 
#include 
#i         


        
相关标签:
7条回答
  • 2020-11-22 15:18

    I believe fflush is only used with output streams.

    You might try fpurge or __fpurge on Linux. Note that fpurge is nonstandard and not portable. It may not be available to you.

    From a Linux fpurge man page: Usually it is a mistake to want to discard input buffers.

    The most portable solution for flushing stdin would probably be something along the lines of the following:

    int c;
    while ((c = getchar()) != '\n' && c != EOF);
    
    0 讨论(0)
提交回复
热议问题