\n in C is the newline character, used to force a newline in text output. It can be used with the \n escape character or inline with std::endl, both of which wrap text to a new line.
What is \n in C
?
In C, \n represents a newline character.
Use
\n Mainly used to force line breaks in text output.
Usage
When using \n in a string, you need to use the escape character \ to escape, for example:
<code class="cpp">std::cout << "第一行" << std::endl; std::cout << "第二行" << std::endl;</code>
or use Inline std::endl:
<code class="cpp">std::cout << "第一行" << std::endl; std::cout << "第二行" << std::endl;</code>
Both methods wrap the output text to a new line.
Example
The following code example demonstrates the use of \n:
<code class="cpp">#include <iostream> int main() { std::cout << "第一行\n"; std::cout << "第二行"; return 0; }</code>
Output
<code>第一行 第二行</code>
Note
The above is the detailed content of What does n mean in c++. For more information, please follow other related articles on the PHP Chinese website!