C++0x 的最新草案 n3126 说:
Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.
...
Within the r-char-sequence of a raw string literal, any transformations performed in phases 1 and 2 (trigraphs, universal-character-names, and line splicing) are reverted.
从技术上讲,这意味着 C++ 预处理器只能识别后跟换行符的反斜杠,但我知道某些 C++ 实现也允许 Windows 或经典 Mac 风格的行结尾。
是否需要符合 C++0x 的实现来保留原始字符串的 r-char-sequence 中紧跟在反斜杠字符 \
之后的换行符序列?也许更好的问题是:是否期望 Windows C++0x 编译器使用 "\\\r\n"
而不是 "\\\n"撤消每一行拼接
?
最佳答案
翻译阶段 1 开始于
Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing newline characters for end-of-line indicators) if necessary. Trigraph sequences (2.3) are replaced [...]
我会将“在第 1 阶段和第 2 阶段执行的任何转换(三字母、通用字符名称和行拼接)”的要求解释为明确不将转换从源文件字符还原为基本的源字符集。相反,源字符稍后会转换为执行字符集,并且您会在那里得到换行符。
关于c++ - 当在 C++0x 原始字符串中取消 CPP 行拼接时,是否需要符合要求的实现来保留原始换行符序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540499/