Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我R"(...)"用来定义一个原始字符串,但是,如果该字符串实际上包含一个原始字符串终止符)",编译器会抱怨。
R"(...)"
)"
例如:
auto tag = R"("(add)")"; // try to get string <"(add)">
我该如何修改它才能正常工作?
原始字符串文字的语法类似于以下内容:
R"<delim>(...)<delim>"
括号旁边的可选分隔符正是您刚刚偶然发现的原因。这是为了让您在文字中包含原始字符串的控制字符。所以添加一个分隔符:
auto tag = R"tag("("add")")tag";