c++的一些评论,比较不错的东西,分享出来!
类型的评论
一个评论是一行(或多行)的文本插入源代码解释代码在做什么。在c++中有两种类型的评论。
//符号开始一个c++单行注释,它告诉编译器忽略一切的尽头。例如:
cout << "Hello world!" << endl; // Everything from here to the right is ignored.
通常,单行注释用于迅速评论一行代码。
cout << "Hello world!" << endl; // cout and endl live in the iostream library cout << "It is very nice to meet you!" << endl; // these comments make the code hard to read cout << "Yeah!" << endl; // especially when lines are different lengths
有注释的右边线可以使代码和注释都难以阅读,特别是如果线长。因此,/ /注释通常置于行是注释。
// cout and endl live in the iostream library cout << "Hello world!" << endl; // this is much easier to read cout << "It is very nice to meet you!" << endl; // don't you think so? cout << "Yeah!" << endl;
/ *和* /对符号代表一个c风格的多行注释。介于两者之间的符号被忽略。
/* This is a multi-line comment. This line will be ignored. So will this one. */
因为一切符号之间被忽略,你有时会看到程序员“美化”他们的多行注释:
/* This is a multi-line comment. * the matching asterisks to the left * can make this easier to read */
多行风格的评论并不巢。因此,以下将会有意想不到的结果:
/* This is a multiline /* comment */ this is not inside the comment */ // ^ comment ends here
规则:不要巢内的其他评论评论。