Comments
来自cppreference.com
< cpp
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
注释充当一系列代码间文档。当插入到程序中时,它们有能效地被编译器忽略,他们被用来作为阅读源代码的人的笔记,仅供。虽然具体的文件是不属于C + +标准,存在几个实用程序,不同的文件格式解析的意见.
Original:
Comments serve as a sort of in-code documentation. When inserted into a program, they are effectively ignored by the compiler; they are solely intended to be used as notes by the humans that read source code. Although specific documentation is not part of the C++ standard, several utilities exist that parse comments with different documentation formats.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 语法
/* comment */
|
(1) | ||||||||
// comment\n
|
(2) | ||||||||
1) 通常被称为“C风格”或“多行”注释。
2) 通常被称为“C++风格”或“单行”注释。
[编辑] C风格
C风格的注释通常用来注释大块文本,但是,他们可以用来注释单行文本。要插入一个C风格的注释,简单地用/*和*/环绕文字,这会使注释的内容被编译器忽略。虽然这不属于C++标准,但是/**和*/通常被用来表示文档块,这是合法的,因为第二个星号将仅被视为注释的一部分。C风格的注释不能嵌套。
C风格注释往往在C和C++混合环境中优先选择,因为它们是唯一可以在C标准(在C99之前)中使用的形式。
[编辑] C++风格
C风格的注释通常用于单行注释,但是,可以将多个C++风格注释放在一起,组成多行注释。C++风格注释告诉编译器忽略//和新行之间的所有内容,这使得它们非常有用。
[编辑] 示例
/* C-style comments can contain multiple lines */ /* or just one */ // C++-style comments can comment one line // or, they can // be strung together int main() { // The below code won't be run // return 1; // The below code will be run return 0; }