endl is a standard library function in C that is used to insert a newline character into the output stream. The specific purpose is as follows: insert a newline character to indicate the beginning of a new line. Used with the << operator to insert a newline character into the output stream. Like '\n', but flushes the stream, immediately displaying output on the console. Is a stream caret that can be used with other stream carets.
endl in C
endl is a standard library function in C, which means "end of line" (line tail). It is a stream insertion character used to insert a newline character into the output stream.
Purpose
endl is used to indicate the beginning of a new line in the output stream. It is often used with the << operator to insert newlines into the output stream. For example:
<code class="cpp">std::cout << "Hello" << endl;</code>
This will output "Hello" and place it on a new line in the output stream.
Differences from '\n'
endl is very similar to '\n' (newline escape character), but there are subtle differences between the two:
Example usage
The following are some example usages of endl:
<code class="cpp">// 输出 "Hello" 并换行 std::cout << "Hello" << endl; // 输出文件 "output.txt" 中的文本 std::ofstream output("output.txt"); output << "Hello" << endl;</code>
Summary
endl is a standard library function in C that inserts a newline character into the output stream. It enables output to be seen immediately on the console and can be used with other stream carets.
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!