c语言中的int f,C中的int fpurge()和int fflush()之间的区别

“… fflush和fpurge将丢弃缓冲区中任何未写入或未读的数据……”:不.

> fflush:

The function fflush forces a write of all buffered data for the given output or update stream via the stream’s underlying write function. The open status of the stream is unaffected.

If the stream argument is NULL, fflush flushes all open output streams.

> fpurge:

The function fpurge erases any input or output buffered in the given stream. For output streams this discards any unwritten output. For input streams this discards any input read from the underlying object but not yet obtained via getc. This includes any text pushed back via ungetc. (P.S.: there also exists __fpurge, which does the same, but without returning any value).

除了对缓冲数据的明显影响之外,您会注意到差异的一个用途是输入流.你可以填充一个这样的流(虽然它通常是一个错误,可能是概念).根据环境的不同,您可能不会刷新输入流(其行为可能未定义,请参阅man page).除了上面提到的差异:1)它们导致错误的情况是不同的,2)fflush可以使用单个语句处理所有输出流,如上所述(这可能非常有用).

至于优点和缺点,我不会引用任何…他们只是工作不同(大多数),所以你应该知道何时使用每一个.

除了功能差异(你要问的是)之外,还有一个便携性差异:fflush是标准函数,而fpurge不是(而__fpurge也不是).

在这里,您有相应的手册页(fflush,fpurge).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值