0

Can someone explain the difference between:

std::cout << "stuff\n";

...and...:

std::cout << "stuff" << std::endl;
Scott Smith
  • 3,900
  • 2
  • 31
  • 63
Engine
  • 5,360
  • 18
  • 84
  • 162
  • 1
    `endl` flushes the buffer. Easily found by searching :p [Here's](http://stackoverflow.com/q/4512631/645270) one (that's actually a duplicate of [this](http://stackoverflow.com/q/213907/645270) one). – keyser Aug 14 '13 at 11:14
  • You also meant `'\n'`, not `"\n"`. Something that is often overlooked when people jump straight to the "flush" answer. – BoBTFish Aug 14 '13 at 11:24

1 Answers1

1

They will generate the same characters (i.e. a carriage return), however std::endl will also flush the stream, which could have an impact on performance if over-used when generating large amounts of output.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242