+ 3
What is the difference between 'endl' and '\n' tag??
4 ответов
+ 17
"\n" is a scape sequence (a string of length 1) which inherited from C and cause a new line operation. "endl" is an object which does the same thing as "\n" and also flushes standard output buffer.
You probably ask what do you mean by flushing the standard output. The following link leads you through some examples.
[https://www.quora.com/What-does-it-mean-to-flush-the-output-stream-in-C++]
+ 4
Not the same thing!!! endl forces a flush on the stream on top of adding the newline character, while just '\n' by itself does not force any flushes. You should know when to flush a stream and when not to, because it can effect performance drastically
+ 1
Yes, they're different.
"\n" ----is just a string of length 1 that gets appended to stdout.
std::endl, ----instead, is an object that will cause to append the newline character ("\n") AND to flush stdout buffer. For this reason it will take more processing.