等价的C自动冲洗的(标准输出刷新每次写入之后)? [英] C equivalent of autoflush (flush stdout after each write)?

查看:119
本文介绍了等价的C自动冲洗的(标准输出刷新每次写入之后)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中,我可以输入:

In Perl, I can type:

$|++;

和任何打印到stdout会自动fflush()的。

and anything printed to STDOUT will be automatically fflush()ed.

有没有用C等效?换句话说,有没有一些方法,我可以告诉标准输入输出,自动fflush每次的printf(标准输出后),它的方式自动冲洗标准错误?

Is there an equivalent in C? In other words, is there some way I can tell stdio to automatically fflush stdout after every printf(), the way it automatically flushes stderr?

推荐答案

尝试 setvbuf用来(标准输出,NULL,_IONBF,0)。它改变了标准输出来缓冲( _IONBF )模式。

Try setvbuf(stdout, NULL, _IONBF, 0). It changes stdout to unbuffered (_IONBF) mode.

这篇关于等价的C自动冲洗的(标准输出刷新每次写入之后)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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