[LC++]Default Arguments

Carlo Wood carlo at alinoe.com
Sat May 11 23:57:05 UTC 2002

On Sat, May 11, 2002 at 01:22:04AM -0400, Paul M Foster wrote:
> > void foo() { std::cout << x->foo << '\n'; }
> In that case, shouldn't it be:
> void foo() { std::cout << x->foo << endl; }

No, there is no reason to flush the output
(stream) every line.

Please note that if you use <stdio.h> (and printf etc)
together with streams, then you need to synchronize
the two.  This synchronization is done (at least till
3.0.4) by flushing per *character*.  This causes a 
dramatic slow down of C++ applications.

You should add


at the start of main in order to stop this per-character
flushing as well.

(see also http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8)

However, even after that I see no reason to flush per-line
in *most* cases.  Especially together with a non-blocking
library like libcw you'd _never_ want to use endl even!
(in example http://libcw.sourceforge.net/io/dbstreambuf.html#avoid)

Carlo Wood <carlo at alinoe.com>

More information about the tuxCPProgramming mailing list