<> wrote in message
news: oups.com...
>
> David Harmon wrote:
>> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
>> wrote,
>> > std::cout << "Hello World" << std::endl;
>>
>> endl is uncalled for there. Please don't teach bad habits.
>> If you want to add a newline, it should be:
>>
>> std::cout << "Hello World\n";
>
> Since std::cout may very well be buffered it is actually prudent to
> pass std::endl instead of '\n'. In this *particular* case, since the
> program exits immediately following the operation it is "unneccisary"
> but it is a GOOD habit
IMO a 'good' habit would be something that is
always 'good' in general (e.g. use consistent
indentation style). But imo 'proper' use of
'endl' depends much upon context. Because of
what it does, using it needlessly can unnecessarily
degrade performance. (i/o is typically the slowest
part of a system -- that's why buffering was invented).
> to get into since in anything more complex than
> a hello world program is going to do more and you should flush your
> outputs when you want them to be sent.
But it's often the case that 'visible' output is not needed
at every occurence of '\n'.
> So, to each his own. I'll answer questions the way I see fit and
> people can learn, or not, what they want.
And others will insert their opinions as they see fit.
FWIW I've still never had the need to use 'endl' with
output streams.
-Mike