I was listening to a google talk by Andrei Alexandrescu on the D programming language when he threw out a one liner about the “endl” fiasco. I just thought endl was the preferred way to signify the end of a line and flush the buffer for a stream. Why is it considered a fiasco? Should I not be using it in my code?
Share
(I assume) He just means that many, especially new, C++ programmers use
std::endlblindly instead of'\n'for newline, flushing unnecessarily frequently and potentially making the performance of their program abysmal.I.e., most people are taught that
std::endlis the canonical way to insert a newline into a stream even though it is very rarely necessary or appropriate to flush it.It is some people’s opinion (*cough*) that
std::endlshouldn’t even be in the standard, as it is so rarely appropriate and not a significant typing savings over'\n' << std::flushanyway.TL;DR(s):
std::endlbuys you nothing except usually worse performance and usually more typing.