The endl manipulator in C is used to output a newline character in the output stream and flush the buffer. Its functions include: outputting newlines, moving the cursor to the next line, flushing the buffer of the output stream, ensuring that the output is displayed immediately
in C endl
endl
in C is a manipulator, used to output a newline character and refresh in the standard output stream (cout
) buffer.
Function
endl
The main functions are:
How to use
To use endl
, just pass it as an output stream (cout
) Just one part:
<code class="cpp">cout << "Hello world!" << endl;</code>
This will print "Hello world!" and move the cursor to the next line. The difference between
and other manipulators. The manipulator similar to
and endl
is '\n'
, which also Output newlines. However, '\n'
does not flush the buffer. This means that calling '\n'
before outputting something else may cause the buffer to fill up, thus delaying output.
Best Practices
When writing code, it is generally recommended to use endl
instead of '\n'
, Because endl
ensures that the output appears on the screen immediately. However, in some cases, avoiding the use of endl
may improve performance, since flushing the buffer is a costly operation.
The above is the detailed content of What does endl mean in c++ and what is its function. For more information, please follow other related articles on the PHP Chinese website!