【问题标题】:Eclipse: comment entire code without it getting cut short by another commentEclipse:注释整个代码,而不会被另一条注释打断
【发布时间】:2017-07-07 08:32:48
【问题描述】:

假设我有以下代码(在 C++ 中,但这可能对问题并不重要):

int main() {
    ....random code....
    /*This is a comment*/
    ....random code....
    return 0;
}

在 Eclipse 中,当我想通过在代码前后放置 /* 和 */ 来注释掉整个代码时,注释会被 */ 在“This is a comment”行的末尾缩短3,所以剩下的代码不加注释。

/*    //<--overall comment starts here
int main() {
    ....random code....
    /*This is a comment*/    //<--overall comment ends here
    ....random code....
    return 0;
}
*/  //<--overall comment SHOULD end here

任何人都知道解决这个问题的方法,还是我只需要处理它或使用 // cmets...?

【问题讨论】:

    标签: c++ eclipse comments block-comments


    【解决方案1】:

    在 C++ 中没有嵌套 cmets 的方法。一种解决方案(特别是如果您不想将大量 /* */ 更改为 //)是使用预处理器,您可以执行类似的操作

    #ifdef SOME_RANDOM_SYMBOL
    
    code that you want to comment here
    
    #endif
    

    只要确保SOME_RANDOM_SYMBOL 没有在您的代码中以某种方式定义即可。

    正如@Caleb 在评论中提到的,你也可以这样做

    #if 0
    
    code that you want to comment here
    
    #endif
    

    但使用符号可以搜索它。

    【讨论】:

    • 或者只是#if 0 ... #endif,但SOME_RANDOM_SYMBOL 允许您在要撤消更改时给它一个易于搜索的名称。
    猜你喜欢
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 2021-08-17
    相关资源
    最近更新 更多