$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Ed Brey (brey_at_[hidden])
Date: 2003-06-04 15:18:42
Paul A. Bristow wrote:
>>
>> cout <<
>> "My first line" "\n"
>> "My second line";
>
> Are you sure that this is more efficient?
>
> cout <<
> "My first line" << endl <<
> "My second line";
>
> has proven LESS efficient and I suspect the flush caused by
> encountering \n will have the same effect. Of course, the
> differences are tiny in practice.
I just did a test using VC7.1: '\n' did not trigger a flush. Assuming that is the correct behavior, that does indeed make the string concatenation method the most efficient.
> I view the newl as much clearer. And the concept that endl actually
> writes the buffered output doesn't seem too complicated.
>
> As a non-C programmer, "\n" looks plain nasty to me :-(
It looks like the intent of newl is to take the place of '\n' is the C++ language, as a way to improve C++ from a syntactical standpoint. I think that such a goal should be handled with an overall view of the language, rather than with just an isolated view of I/O streams. The larger question would address how the '\n' replacement interacts with strings, including string concatenation and operator overloading.
I'd say it would be an interesting issue to raise on comp.lang.c++, except for one thing: it would be hard to demonstrate how one abbreviation is better than another and worth a language change, especially when complicated by the precipitating changes required to harmonize '\t', '\r', etc.