On Monday 03 April 2006 11:58 am, Stefan Hundhammer wrote:
On Monday 03 April 2006 17:18, Jerry Feldman wrote:
I've seen a number of documents and code that prefers to use the newline character ("\n" or '\n') rather than std::endl In the general case, the issue is that endl forces a buffer flush where '\n' does not, and therefore using the newline is more efficient. However, using endl is more portable. Either way works fine on Linux. Comments...
It's not only portability, it's also about buffer flushing:
http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2
OTOH this might be a reason to advise against std::endl, too:
http://llvm.org/docs/CodingStandards.html#hl_avoidendl I was looking for something like this that is specific and to the point. Some C++ texts teach std::endl, and others teach that using the newline characters. I knew that endl did the buffer flush. The main reason I asked is to get some good definitive answers since I do occasionally teach C++ (although I am primarily a C programmer). -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9