是否函数setbuf()影响清点? [英] Does setbuf() affect cout?
问题描述
再一次,我的老师是不能回答我的问题。我知道谁可能是能够...
Yet again, my teacher was unable to answer my question. I knew who may be able to...
所以,我从来没有真正学会C.在C ++中,我会很明显,使用一个COUT语句的所有时间。在最近的一次任务,我的老师告诉我们,以确保把
So, I've never really learned C. In C++, I would, obviously, use a cout statement all of the time. In a recent assignment, my teacher told us to make sure to put
setbuf( stdout , NULL );
在的主要(),以获得无缓冲输出,从而使我们看到正确的输出。顶端
at the top of main() in order to get an unbuffered output, thus allowing us to see the output properly.
我的问题是这样的:将本声明影响的cout语句,或者干脆一个printf()语句,我打电话?
My question is this: will this statement affect a cout statement, or simply a printf() statement that I call?
在此先感谢!
推荐答案
默认情况下,输入输出流和标准输入输出是同步的。 参考。
By default, iostreams and stdio are synchronised. Reference.
这并不意味着手动调节STDIO缓冲是一个好主意,但!你不妨利用的std :: ENDL
或的std ::冲洗
(从< ostream的>
),这可能会帮助你。如,
This doesn't mean that manually adjusting the stdio buffering is a good idea, though! You may wish to utilise std::endl
or std::flush
(from <ostream>
), which may help you. e.g.,
std::cout << "Hello, world!" << std::endl;
或
std::cout << "Hello, world!\n" << std::flush;
这两个做同样的事情。 ( 的std :: ENDL
=打印底线,然后冲水。)
Both of these do the same thing. (std::endl
= print endline, then flush.)
这篇关于是否函数setbuf()影响清点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!