c高手,"fflush(stdout)"是什么意思,没有遇到过啊(在线)

2025-02-27 02:03:39
推荐回答(3个)
回答1:

刷新输出缓冲区
其实这里不需要,因为遇到输入时会自动刷新缓冲区,使缓冲区内容置空

回答2:

清空输出缓冲区,并把缓冲区内容输出

回答3:

函数名: fflush
功 能: 清除一个流
用 法: int fflush(FILE *stream);
程序例:

#include
#include
#include
#include

void flush(FILE *stream);

int main(void)
{
FILE *stream;
char msg[] = "This is a test";

/* create a file */
stream = fopen("DUMMY.FIL", "w");

/* write some data to the file */
fwrite(msg, strlen(msg), 1, stream);

clrscr();
printf("Press any key to flush\
DUMMY.FIL:");
getch();

/* flush the data to DUMMY.FIL without\
closing it */
flush(stream);

printf("\nFile was flushed, Press any key\
to quit:");
getch();
return 0;
}

void flush(FILE *stream)
{
int duphandle;

/* flush the stream's internal buffer */
fflush(stream);

/* make a duplicate file handle */
duphandle = dup(fileno(stream));

/* close the duplicate handle to flush\
the DOS buffer */
close(duphandle);
}