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

规则:不要巢内的其他评论评论。

转载于:https://www.cnblogs.com/linyanhuas/p/plielso.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值