endl means "end of line" in C and is used to insert a newline character in the output stream and start a new line. Its working principle is: force the output stream buffer to be refreshed. Inserts a newline character and moves the output pointer to the next line.
endl meaning in C
endl is a keyword in C, used in the output stream Insert a newline character into . It stands for "end of line" and starts a new line in the output.
Usage
endl can be used like a normal function on the standard output stream cout or any other output stream object. The syntax is as follows:
<code class="cpp">output_stream << endl;</code>
Among them, output_stream is the output stream object to which newlines are to be inserted.
How it works
endl forces the buffer of the output stream to be flushed by calling a member function named flush(). This means that any data that has not yet been written to the output device is sent out immediately. Inserting a newline character also means that the output pointer will move to the next line.
Example
The following example uses endl to print "Hello World" in the terminal, and then prints "C " on a new line:
<code class="cpp">#include <iostream> using namespace std; int main() { cout << "Hello World" << endl; cout << "C++" << endl; return 0; }</code>
Output results :
<code>Hello World C++</code>
Supplementary Note
The above is the detailed content of What does endl mean in c++. For more information, please follow other related articles on the PHP Chinese website!