Escape sequences
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
使用转义序列来定义某些特殊字符在字符串常量.
Original:
Escape sequences are used to define certain special characters within string literals.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
下面的转义序列
Original:
The following escape sequences are available:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| Escape sequence |
Description | Representation |
|---|---|---|
\'
|
single quote | byte 0x27
|
\"
|
double quote | byte 0x22
|
\?
|
question mark | byte 0x3f
|
\\
|
backslash | byte 0x5c
|
\0
|
null character | byte 0x00
|
\a
|
audible bell | byte 0x07
|
\b
|
backspace | byte 0x08
|
\f
|
form feed - new page | byte 0x0c
|
\n
|
line feed - new line | byte 0x0a
|
\r
|
carriage return | byte 0x0d
|
\t
|
horizontal tab | byte 0x09
|
\v
|
vertical tab | byte 0x0b
|
\nnn
|
arbitrary octal value | byte nnn
|
\xnn
|
arbitrary hexadecimal value | byte nn
|
\u
|
arbitrary Unicode的 value. May result in several characters. |
code point U+nnnn
|
\U
|
arbitrary Unicode的 value. May result in several characters. |
code point U+nnnnnnnn
|
[编辑] 注释
新行字符
\n在文本模式下I / O使用时,具有特殊的意义,它被转换为特定的OS-换行符字节或字节序列.Original:
The new-line character
\n has special meaning when used in text mode I/O, it is converted to the OS-specific newline byte or byte sequence.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
八进制转义序列有三位八进制数的限制,但终止的第一个字符是不是一个有效的八进制数字,如果遇到早晚.
Original:
Octal escape sequences have a limit of three octal digits, but terminate at the first character that is not a valid octal digit if encountered sooner.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
十六进制转义序列没有长度的限制和终止的第一个字符是不是一个有效的十六进制数字。如果一个十六进制转义序列表示的值不适合在这个字符串中的字符类型的值所代表的范围内文字(char,char16_t,char32_t,或wchar_t),其结果是不确定的。
Original:
Hexadecimal escape sequences have no length limit and terminate at the first character that is not a valid hexadecimal digit. If the value represented by a single hexadecimal escape sequence does not fit the range of values represented by the character type used in this string literal (char, char16_t, char32_t, or wchar_t), the result is unspecified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
一个普遍的字符的名称在一个狭窄的字符串文字可以映射到一个以上的字符,由于多字节编码.
Original:
A universal character name in a narrow string literal may map to more than one char due to multibyte encoding.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
转义序列\?的问号是用来防止三字母在字符串常量被解释:编译为一个字符串,如"??/""\",但如果第二个问号是逃了出来,在"?\?/",就成了"??/"
Original:
The question mark escape sequence \? is used to prevent 三字母 from being interpreted inside string literals: a string such as "??/" is compiled as "\", but if the second question mark is escaped, as in "?\?/", it becomes "??/"
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <iostream> int main() { std::printf("This\nis\na\ntest\n\nShe said, \"How are you?\"\n"); }
Output:
This is a test She said, "How are you?"

