What is the purpose of “endl” in C++?

In C++, endl is a manipulator used for output streams, which inserts a newline character and flushes the output buffer. When endl is used, it inserts a newline character in the output and immediately flushes the output buffer, ensuring that the output is displayed on the terminal right away. Compared to using ‘\n’, endl forces the output buffer to be flushed, so it can be used to ensure data is outputted when needed (such as before program termination). Ending a line of output with endl will guarantee that the output is complete when the program finishes.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds