I'm brand new to coding and programming (started today actually). I've been watching a few videos and reading the beginning to a few books to see which I can click with, but I'm having trouble understanding some of it.
One of the videos utilized endl
and another utilized \n
in the basic "Hello World" introduction. I wanted to know more about the differences between the two.
So, I understand that the difference between endl
and \n
is that endl
will flush the code while \n
will not, which makes endl
slower. That much I can search for on Google.
However, when searching for flushing C++, I'm not able to make heads or tails of what it means because of the jargon.
What does it mean to flush, and when and why would you want to do it? What is a buffer?
Please explain it in a very basic way, if you can.
To flush, means to empty the buffer.
Now, buffer is temporary storage area for storing data.
Both endl and \n can be used to print newline character but there is minor difference between these two :
In case of endl, buffer is cleared by usage of internal call to flush the buffer
In case of \n, newline is printed but buffer is not flushed as no extra call is made
So performance-wise, endl is better than \n