In
C, \n is a newline character, moving the cursor to the beginning of the next line; \t is a tab character, moving the cursor to the next tab stop. They are used to format output, \n creates new lines, and \t indent text.
The difference between \n and \t in C
In C, \n
and \t
are escape sequences that represent special characters.
\n (newline character):
\t (tab character):
How to use
These escape sequences are commonly used to format output:
Newline character (\n):
cout << "Line 1" << endl;
will wrap after "Line 1". Tab character (\t):
cout << "\tColumn 1" << endl;
will indent "Column 1" by one tab stop. Example
The following code demonstrates the use of \n
and \t
Usage:
<code class="cpp">#include <iostream> using namespace std; int main() { // 换行符 cout << "行 1" << endl; cout << "行 2" << endl; // 制表符 cout << "列 1\t列 2" << endl; return 0; }</code><p>Output: </p> <pre class="brush:php;toolbar:false"><code>行 1 行 2 列 1 列 2</code>
The above is the detailed content of The difference between /n and /t in c++. For more information, please follow other related articles on the PHP Chinese website!