Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

stdio - C equivalent of autoflush (flush stdout after each write)?

In Perl, I can type:

$|++;

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...