You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ide/include-cleanup-config.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The dropdown filter is set to Build + IntelliSense. A warning is visible: VCIC00
40
40
41
41
**Dimmed**
42
42
43
-
Include Cleanup shows unused headers by dimming the line of the unused header file in the code editor. Hover your cursor over the dimmed `#include` to bring up the quick action menu and choose **Show potential fixes**, or click on the lightbulb dropdown, to see actions related to the unused file.
43
+
Include Cleanup shows unused headers by dimming the line of the unused header file in the code editor. Hover your cursor over the dimmed `#include` to bring up the quick action menu and choose **Show potential fixes**, or click on the light bulb dropdown, to see actions related to the unused file.
44
44
45
45
:::image type="complex" source="media/include-cleanup-dimmed-include.png" alt-text="A screenshot of a dimmed #include < iostream > line.":::
46
46
The line for #include < iostream > is dimmed because the line of code that uses iostream is commented out. That line of code is // std::cout << "charSize = " << charSize; The quick action menu is also visible for this line. It says the #include < iostream > isn't used in this file, and has a link to Show potential fixes.
Copy file name to clipboardExpand all lines: docs/ide/include-cleanup-overview.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Include Cleanup is on by default. To learn how to configure it, see [Config C/C+
21
21
First some terminology:
22
22
23
23
- A direct header is a header that you explicitly `#include` in your code.
24
-
- An indirect header is a header that you don't explicitly `#include`, but that is included by a header file that you do directly include. We also say that an indirect header is included `transitively`.
24
+
- An indirect header is a header that you don't explicitly `#include`. Instead, a header file that you do directly include, includes it. We also say that an indirect header is included `transitively`.
25
25
26
26
Include Cleanup analyzes your code and determines which headers aren't used and which are indirectly included. Consider the following header file:
27
27
@@ -105,16 +105,16 @@ The tool doesn't update the comments, but you can see that the code is now using
105
105
106
106
## Best practice
107
107
108
-
Don't remove what appear to be unused header files without first adding indirectly included header files. That's because your code may rely on indirect includes in a header file that is otherwise unused. Add transitively used headers first. Then, when you remove unused headers, you won't have compilation errors due to missing header files that were included indirectly by a header file you've removed.
108
+
Don't remove what appear to be unused header files without first adding indirectly included header files. That's because your code may rely on indirect includes in a header file that is otherwise unused. Add transitively used headers first. Then, when you remove unused headers, you don't get compilation errors due to missing header files that are included indirectly by a header file you've removed.
109
109
110
-
One way to do this is to set the Include Cleanup setting for **Add missing includes suggestion level** to **Suggestion** (**Tools** > **Options** > **Text Editor** > **C/C++** > **Code Cleanup**). Also set **Remove unused includes suggestion level** to **Suggestion**. Then:
110
+
One way to do this is to set the Include Cleanup setting for **Add missing includes suggestion level** to **Suggestion** (**Tools** > **Options** > **Text Editor** > **C/C++** > **Code Cleanup**). Also set **Remove unused includes suggestion level** to **Suggestion**. Then:
111
111
112
112
1. In the error list, make sure the filter is set to **Build + IntelliSense**.
113
113
1. Look for instances of "Content from #include x is used in this file and transitively included."
114
-
1. Hover your cursor over a line with the suggestion. From the lightbulb dropdown, select **Add all transitively used includes**.
114
+
1. Hover your cursor over a line with the suggestion. From the light bulb dropdown, select **Add all transitively used includes**.
115
115
1. Repeat these steps in your project until all suggestions regarding transitive includes are addressed.
116
116
1. Remove unused includes: in the error list, look for an instance of "#include x is not used in this file."
117
-
1. Hover your cursor over the unused header. From the lightbulb dropdown, select **Remove all unused includes**.
117
+
1. Hover your cursor over the unused header. From the light bulb dropdown, select **Remove all unused includes**.
118
118
1. Repeat these steps in your project until all Include Cleanup suggestions are addressed.
119
119
120
120
In this brief overview, you've seen how Include Cleanup can help you remove unused headers, and add headers that were indirectly included. This helps you keep your code clean, potentially build faster, and reduces the brittleness of your code.
0 commit comments