views:

88

answers:

4

Hi

In such code, what it is called, \\n like this?

cout<<"Hello\\n \'world\'!";

What's the basic rule about such characters?

+8  A: 

\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.

codaddict
Your literal backslash is missing something ...
Daniel Newby
+1  A: 

\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).

Justin Ethier
The backslash before `n` is escaped here, so no.
Georg Fritzsche
+1  A: 

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.

Vlad
+1  A: 

In computing, we call those escape characters.

shinkou