0

Can someone explain the difference between:

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

...and...:

std::cout << "stuff" << std::endl;
Scott Smith
  • 3,639
  • 2
  • 30
  • 59
Engine
  • 5,200
  • 15
  • 75
  • 150
  • 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
  • 118,129
  • 19
  • 204
  • 237