64,654
社区成员
发帖
与我相关
我的任务
分享
Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant.
Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark ("). The following table lists the ANSI escape sequences and what they represent.
Note that the question mark preceded by a backslash (\?) specifies a literal question mark in cases where the character sequence would be misinterpreted as a trigraph. See Trigraphs for more information.
Escape Sequences
Escape Sequence Represents
\a
Bell (alert)
\b
Backspace
\f
Formfeed
\n
New line
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\'
Single quotation mark
\"
Double quotation mark
\\
Backslash
\?
Literal question mark
\ooo
ASCII character in octal notation
\xhh
ASCII character in hexadecimal notation
\xhhhh
Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal.
For example, WCHAR f = L'\x4e00' or WCHAR b[] = L"The Chinese character for one is \x4e00".
Microsoft Specific
If a backslash precedes a character that does not appear in the table, the compiler handles the undefined character as the character itself. For example, \c is treated as an c.