Equivalent of #region for C++

前端 未结 10 1043
無奈伤痛
無奈伤痛 2020-12-24 04:17

What\'s the C++ equivalent of #region for C++ so I can put in custom code collapsible bits and make my code a little easier to read?

相关标签:
10条回答
  • 2020-12-24 05:06

    The first answer from this question mentions another alternative. It is not applicable in all situations, though.

    Method: Use {...} instead which natively supports code collapsing in Visual Studio.

    1. Enable option: Tools -> Options -> Text Editor -> C/C++ -> Formatting -> OutLine Statement Blocks -> True.

    2. Put your in different scopes {...}, then it will collapse the code in different scopes:

    Scoped code collapsing example

    0 讨论(0)
  • 2020-12-24 05:10

    Just an addition to other answers. The region definition varies from IDE to IDE.

    For Mac development in Xcode you can use a pragma:

    #pragma mark
    
    0 讨论(0)
  • 2020-12-24 05:11

    In addition to #pragma region#pragma endregion for Visual Studio, many IDEs support the following syntax for regions in any {}-delimited, //-commented language:

    //{ Region header text.
    …
    //}
    

    Notable examples include Code::Blocks and FlashDevelop, and any other editor that uses the Scintilla editing component, such as Notepad++, Geany, Komodo Edit, and many more.

    0 讨论(0)
  • 2020-12-24 05:12

    There isn't an equivalent in C++. However IDEs should be able to collapse sections.

    It is also possible to use something like this:

    #pragma region
    
    #pragma endregion A comment about the region.
    

    But probably not very portable

    0 讨论(0)
提交回复
热议问题