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?
相关问题
- Sorting 3 numbers without branching [closed]
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- How to compile C++ code in GDB?
There is no equivalent. The
#region
feature is part of the C# specification.C++ has no such equivalent. You could possibly mimic it with specially formatted comments, but this would be editor specific.
For Visual Studio you can use:
There is no equivalent.
Most good editors or IDEs will let you collapse functions, if not also
if
/else
/while
/for
/etc.C++Builder does support this, but you must declare the region as:
You must use end_region for C++Builder, but it will work, and it will collapse the region!
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.
Enable option: Tools -> Options -> Text Editor -> C/C++ -> Formatting -> OutLine Statement Blocks -> True.
Put your in different scopes {...}, then it will collapse the code in different scopes:
In addition to
#pragma region
…#pragma endregion
for Visual Studio, many IDEs support the following syntax for regions in any{}
-delimited,//
-commented language: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.
I've been using
for several projects during the last couple of years and that suits me (including collapsible blocks). as an addition, i can disable the block using #define ANY_NAME_FOR_THIS_REGION just above it.