Escape Sequences

(这篇随笔是 C++ Primer 5th ed. pp.39-40的摘录)

Some characters, such as backspace or control characters, have no visible image. Such characters are non printable.

Other characters (single and double quotation marks, question marks, and backlash) have special meaning in the language. Our programs cannot use any of these characters directly. Indeed, we use an escape sequence to represent such characters. An escape sequence begins with a backslash ('\'). The language defines several escape sequences:

  newline      \        horizontal tab      \t      alert (bell)    \a

  vertical tab    \v         backspace        \b       double quote    \"

  backslash      \\        question mark      \?      single quote    \'

  carriage return  \r        formfeed         \f

----------------------------------------------------------------------------------------------------------------------------

We can also write a generalized escape sequence, which is \x followed by one or more hexadecimal digits or a \

followed by one, two, or three octal digits. The value represents the numerical value of the character.

Note that if a \ is followed by more than three octal digits, only the first three are associated with the \. In contrast, \x uses up all the hex digits following it.

Ordinarily, haxadecimal characters with more than 8 bits are used with extended characters sets using one of the following prefixs:

  Prefix    Meaning            Type

  u      Unicode 16 character       char16_t

  U      Unicode 32 character       char32_t

  L      wide character         wchar_t

  u8      utf-8 (string literals only)     char

--------------------------------------------------------------------------------------------------------------------------

 

posted @ 2015-11-27 00:02  Pat  阅读(290)  评论(0编辑  收藏  举报