为什么fflush()不认为是安全的? [英] Why is fflush() not considered safe?

查看:326
本文介绍了为什么fflush()不认为是安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 fflush()不认为是安全的?有人告诉我,它显示未定义的行为?如果是这样,什么是fflush()选择?

Why is fflush() not considered safe? I have been told that it shows undefined behaviour? If so, what is the alternative to fflush()?

推荐答案

您可能被告知 fflush(标准输入)是不确定的,这就是正确的。但 fflush 是去要冲洗其他流,如标准输出例如方式。

You were probably told fflush(stdin) is undefined and that's right. But fflush is the way to go for other streams that you want to flush, like stdout for example.

要澄清,流必须用于输出。标准说:

To clarify, the stream must be used for output. The standard says:

如果流指向一个输出流或更新流,其中
  最近一次操作是没有输入,fflush函数导致任何
  该流未写入的数据被传递到主机环境
  要被写入该文件;否则,行为是不确定的。

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.

后来的标准包括这种明确为未指定行为:

Later the standard includes this explicitly as "Unspecified behavior":

有关fflush函数指向一个输入流或一个流
  更新流的其中最近一次操作是输入

The stream for the fflush function points to an input stream or to an update stream in which the most recent operation was input

这篇关于为什么fflush()不认为是安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆