关于使用#pragma区在Visual Studio崩溃code座 [英] About collapsing code block in Visual Studio using #pragma region
问题描述
在VisualStudio中,当你写一个函数就可以折叠为轮廓,每个人都知道这一点。你也可以使用的#pragma区域
和的#pragma endregion
来手动指定code区使它能坍方。但是我发现,如果有倒塌code块是在的#pragma区域
,他们不能再崩溃的问题。有什么办法解决呢?
In VisualStudio, when you write a function it can collapse to outlines, everyone knows it. Also you can use #pragma region
and #pragma endregion
to manually specify a code region so that it can collapse. However I found a problem that, if any collapsed code blocks are within the #pragma region
, they cannot collapse anymore. Is there any way to solve it?
推荐答案
有几个不同于也更好,灵活的方式的#pragma区域
你可以做垮code在VS:
There are several other also better and flexible ways than #pragma region
you can do to collapse code in VS:
方法1:使用 {...}
而不是它本身支持code在VS崩
Method 1: Use {...}
instead which natively supports code collapsing in VS.
-
启用选项:
工具 - >文字编辑器 - > C / C ++ - > Formatting->轮廓声明Blocks->真
把你在不同的范围 {...}
,那么它会崩溃在不同范围内的code:
Put your in different scopes {...}
, then it will collapse the code in different scopes:
方法2:使用键盘快捷键折叠您想code:
Method 2: use keyboard shortcuts to collapse code you want:
-
<大骨节病> CTRL 骨节病> + <大骨节病> M 骨节病> + <大骨节病> 0 骨节病>将折叠所有。
CTRL + M + O will collapse all.
<大骨节病> CTRL 骨节病> + <大骨节病> M 骨节病> + <大骨节病>→骨节病>将全部展开。
CTRL + M + L will expand all.
<大骨节病> CTRL 骨节病> + <大骨节病> M 骨节病> + <大骨节病> P 骨节病>将全部展开,并禁用概述。
CTRL + M + P will expand all and disable outlining.
<大骨节病> CTRL 骨节病> + <大骨节病> M 骨节病> + <大骨节病> M 骨节病>将折叠/展开当前部分。
CTRL + M + M will collapse/expand the current section.
这是值得指出的是方法#1工作更好地为普通code片段。对于函数,因为类似我们不能在里面的C ++ 一个函数的函数>,我们不能把通过 {...}
。幸运的是,我们仍然可以通过为每个范围创建命名空间的使用方法#1功能。或者干脆,使用方法#2。
It is worthy noting that method #1 works better for plain code snippets. For functions, because similar to that we cannot have functions inside functions in C++, we cannot put functions in scope defined by {...}
. Fortunately, we can still use method #1 for functions by creating namespaces for each scope. Or simply, use method #2.
这篇关于关于使用#pragma区在Visual Studio崩溃code座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!