Hi
In such code, what it is called, \\n
like this?
cout<<"Hello\\n \'world\'!";
What's the basic rule about such characters?
Hi
In such code, what it is called, \\n
like this?
cout<<"Hello\\n \'world\'!";
What's the basic rule about such characters?
\n
is an escape sequence
to print a new line. Now if you want to print a \n
( a literal \n
that is a slash followed by an n) on the screen you need to escape the \
like \\
. So \\n
will make \n print on the screen.
\n
is a newline character; it signals the end of a line of text.
\\
is an escaped backslash, so it will print \
. So \\n
will just print a literal "\n" to the console.
For more information about C escape sequences, see Escape Sequences (MSDN).
I suppose your question is about escape characters? They are a part of string literal declarations, not stream operations. See documentation for more details on escape sequences.
In particular: \n
signifies new line, \t
signifies TAB character, \"
signifies a quote character.