如何在//注释中转义反斜杠 [英] How to escape backslash in // comment

查看:167
本文介绍了如何在//注释中转义反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条以反斜杠结尾的评论。

I have a comment that ends with backslash. Something like

...

// use \

..

Clang(++)警告我,这是多行注释

Clang(++) warned me, that this is multi-line comment

warning: multi-line // comment [-Wcomment]
    // use \
           ^

所以我尝试在末尾添加一些空格,但没有帮助。我可以以某种方式转义反斜杠吗?

So I try add some whitespace at the end, but didn't help. Can I escape backslash somehow?

推荐答案

问题的根源是行继续的定义。

The foundation of the issue is the definition of a line continuation.

当一行以 backslash-newline 组合或< backslash><& ; whitespace>< newline> 组合,编译器会将文本的下一行附加到当前文本行。这可以通过宏进行演示:

When a line ends with a backslash-newline combination or <backslash><whitespace><newline> combination, the compiler appends the next line of text to the present line of text. This can be demonstrated with macros:

#define ME {\
cout << "me\n" \
}

以上将被视为单个行:

#define ME {cout << "me\n"}

编译器在抱怨,因为您的 //注释扩展到了下一行是因为 \连续字符。

The compiler is complaining because your "//" comment extends to the next line because the '\' continuation character.

解决方案:

将其他字符放在 \之后。

示例:

Solution:
Put other characters after the '\'.
Examples:

  '\'
  \ ending character

这篇关于如何在//注释中转义反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆