【发布时间】:2020-11-15 17:51:33
【问题描述】:
在 Python 中,有两种类型的 cmets。
第一个使用#(单行cmets)
# This is a comment
This_is_not()
另一个使用"""/'''(多行cmets)
"""
This is a comment
"""
'''
Yet another comment
'''
NOT_a_comment()
在 C++ 中,有两种类型的 cmets。
第一次使用//(单行cmets)
// This is a comment
This_is_not_a_comment();
另一个使用/*/*/(多行cmets)
/*
This is a comment
*/
This_is____well_you_get_the_idea();
我的问题是,
我可以在 C++ 中使用字符串作为 cmets 吗?
如果我这样做了,gcc 会给我一个警告。
warning: statement has no effect [-Wunused-value]
"This is a comment";
^~~~~~~~~~~~~~~~~~~
但是,如果我只是忽略警告(可能是-Wno-unused-value)就可以了,对吧?
【问题讨论】:
-
技术上它们也不是 Python 中的 cmets。它们是字符串文字。
-
因为评论的语法不同是
C++和python -
为什么将“""...""" 称为 cmets?他们是 f.e.用作记录字符串 - 如果放在其他任何地方,它们只是被创建和销毁的字符串,因为没有实例引用它们......
-
问题的前提是有缺陷的。 Python 多行字符串文字 (
"""...""") 不是 cmets。 -
Python 的documentation 说:“注释以不属于字符串文字的哈希字符 (#) 开头,并在物理行的末尾结束。” Python 中没有其他注释语法。
标签: python c++ string comments