我不知道是我漏掉了什么,还是它真的不存在。在C++11标准中,添加了原始字符串字面量:
string s = "\\w\\\\\\w"; // I hope I got that right
string s = R"(\w\\\w)"; // I'm pretty sure I got that right
我所有尝试使用原始字符字面量的努力都失败了:
constexpr char bslash = R('\'); // error: missing terminating ' character
constexpr char bslash = R'(\)'; // error: 'R' was not declared in this scope
第二次尝试被认为是一个多字符常量!我发现类似于原始字符字面量的使用方式只有这种方法:
constexpr char slash = *R"(\)"; // All Ok.
但是我不喜欢这种表示法(解除引用字符串字面量以存储第一个元素的副本),因为它有点令人困惑。
那么问题是什么?
- 原始字符字面量存在吗?(我没有找到任何关于它们的信息,所以我几乎可以确定它们不存在)
- 如果它们存在:我应该如何编写原始字符字面量?
- 如果它们不存在:为什么?是否有理由添加原始字符串字面量但避免添加原始字符字面量?
char a = '\\'; // 我相当确定我写对了
。 - Cássio Renan