Home  >  Article  >  Backend Development  >  What does \n mean in c++

What does \n mean in c++

下次还敢
下次还敢Original
2024-05-01 16:42:14575browse

\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 does \n mean in c++

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

  • \n Only valid in text output, not binary files.
  • On Windows systems, \n is converted to \r\n because Windows systems use different newline conventions.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does \0 mean in c++Next article:What does \0 mean in c++