Home > Backend Development > C++ > Usage of \n in c++

Usage of \n in c++

下次还敢
Release: 2024-04-28 18:39:12
Original
737 people have browsed it

In C, the character "\n" represents a newline character and can be used in the following ways: Use cout << "\n" to break a newline. Use the endl manipulator to both wrap lines and refresh the output stream.

Usage of \n in c++

Usage of \n in C

In the C programming language, the character '\n' represents a newline character . It is used to move the output to the next line.

Usage:

  • You can use cout << "\n" to move the output to the next line.
  • You can use the endl manipulator, which moves the output to the next line and flushes the output stream.

Example:

<code class="cpp">#include <iostream>

using namespace std;

int main() {
    cout << "Hello" << endl;
    cout << "World" << "\n";

    return 0;
}</p>
<p>Output:</p>
<pre class="brush:php;toolbar:false"><code>Hello
World</code>
Copy after login

Note:

  • The usage of \n may vary on different operating systems. For example, in Windows \n corresponds to \r\n, while on UNIX/Linux systems \n represents a newline.
  • endl and "\n" are equivalent in most cases, but endl can provide better portability in some cases.

The above is the detailed content of Usage of \n in c++. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template