0

As I understand \n means a new line and endl means end of the line.I have read somewhere that using endl(stream manipulator) is advantageous.Which one should be preferred and when?

Richard Rublev
  • 7,718
  • 16
  • 77
  • 121

3 Answers3

3

The only difference is that std::endl flushes the output buffer, and '\n' doesn't. If you don't want the buffer flushed frequently(performance issue) then use '\n'

Nishant
  • 1,635
  • 1
  • 11
  • 24
1

std::endl also flushes the stream it's put on, while '\n' doesn't.

Depends on what you want, to judge which is better to use.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
0

\n merely ends the line. endl ends the line and also flushes the output stream. endl is advantageous when you explicitly care about flushing your output buffer.

HighVoltage
  • 722
  • 7
  • 25