Escape sequences
Escape character syntax
An escape sequence contains a backslash (\) symbol followed by one of the escape sequence characters or an octal or hexadecimal number. A hexadecimal escape sequence contains an x followed by one or more hexadecimal digits (0-9, A-F, a-f). An octal escape sequence uses up to three octal digits (0-7). The value of the hexadecimal or octal number specifies the value of the wanted character or wide character.
The escape sequences and the characters they represent are:
Escape sequence | Character represented |
---|---|
\a | Alert (bell, alarm) |
\b | Backspace |
\f | Form feed (new page) |
\n | New-line |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\' | Single quotation mark |
\" | Double quotation mark |
\? | Question mark |
\\ | Backslash |
The value of an escape sequence represents the member of the character set used at run time. Escape sequences are translated during preprocessing. For example, on a system using the ASCII character codes, the value of the escape sequence \x56 is the letter V. On a system using EBCDIC character codes, the value of the escape sequence \xE5 is the letter V.
Use escape sequences only in character constants or in string literals. An error message is issued if an escape sequence is not recognized.
cout << "The escape sequence \\n." << endl;
The escape sequence \n.