0

Many people say that in C++ endl is much slower than \n when printing a string. They explain that endl flushes the buffer and \n doesn't. In the book C Primer Plus it's said that

"Sending the output from the buffer to the screen or file is called flushing the buffer."

and that

"The standard C rules for when output is sent from the buffer to the screen are clear: It is sent when the buffer gets full, when a newline character is encountered, or when there is impending input."

So isn't technically printing an newline character flushing the buffer and still why is endl slower ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
0xZ3RR0
  • 389
  • 3
  • 10
  • 14
    To my knowledge, `endl` is a C++ only construct - so the C Primer Plus might not be the best place to check for its behavior. – tonysdg Sep 15 '15 at 16:26
  • 1
    Your quote about "the standard C rules for when output is sent from the buffer" are wrong. And the standard C rules only matter when iostreams are synchronized with stdio (which basically requires that iostream foregos its buffering mechanism and immediately forwards everything along to stdio calls). –  Sep 15 '15 at 16:34
  • Also see e.g. http://stackoverflow.com/a/8311177/440558 – Some programmer dude Sep 15 '15 at 16:37

0 Answers0