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
  • 6,495
  • 12
  • 58
  • 100

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,615
  • 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.

πάντα ῥεῖ
  • 85,314
  • 13
  • 111
  • 183
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
  • 702
  • 6
  • 24