Home > Article > Backend Development > The role of \n in c++
\n in C represents a newline character, which causes the compiler to move the output cursor to the beginning of the next line, thus forming a new line. Its functions include: creating new lines, formatting output, and controlling output flow.
The role of \n in C
In C language, the escape character \n represents a newline character. It causes the compiler to move the output cursor to the beginning of the next line, thus creating a new line.
Usage
To insert a newline character, you can use the \n character in the string. For example:
<code class="cpp">std::cout << "Hello" << std::endl;</code>
The above code will output:
<code>Hello</code>
Function
\n The escape character has the following effect:
Examples
Here are some examples of using the \n escape character:
<code class="cpp">std::cout << "Line 1" << std::endl; std::cout << "Line 2" << std::endl;</code>
<code class="cpp">std::cout << "Item 1: " << std::left << std::setw(10) << 10 << std::endl; std::cout << "Item 2: " << std::left << std::setw(10) << 20 << std::endl;</code>
<code class="cpp">std::cout << "This will be flushed immediately" << std::flush;</code>
The above is the detailed content of The role of \n in c++. For more information, please follow other related articles on the PHP Chinese website!