Re: "endl and "\n"

From: Sharad Kala (no__spam.sharadk_ind_at_yahoo.com)
Date: 07/07/04


Date: Wed, 7 Jul 2004 13:40:55 +0530


"dover" <doverkn@close.com> wrote in message
news:M%NGc.207212$Gx4.34922@bgtnsc04-news.ops.worldnet.att.net...
> For the code, outputfile << *p << endl;
>
> Someone suggests: Don't use endl here; it is flushing output stream every
> time. Use plain '\n'.
>
> What's the difference of using "endl" and "\n" above? What's the meaning
of
> flushing output stream? Isn't that what we want?

Somebody had already given you the answer ;-), it is flushing output stream
every time. Buffering here means that not everything that you write into the
stream goes to the external device, instead IOStreams is buffering (storing)
it and at some point they flush it to the external device. This boosts the
efficiency. With every endl you flush the stream which may be an overkill.

-Sharad