1

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

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

What's the basic rule about such characters?

codaddict
  • 445,704
  • 82
  • 492
  • 529
skydoor
  • 25,218
  • 52
  • 147
  • 201

4 Answers4

9

\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
  • 445,704
  • 82
  • 492
  • 529
1

\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
  • 131,333
  • 52
  • 229
  • 284
1

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
  • 35,022
  • 6
  • 77
  • 199
1

In computing, we call those escape characters.

shinkou
  • 5,138
  • 1
  • 22
  • 32