#include cleanup in Visual Studio
![thumbnail](https://images.nomadterrace.com/articles/ce8cb1a8-200d-11ee-8980-0a58a9feac02.gif)
#include Cleanup in Visual Studio
Visual Studio 17.7 Preview 3 introduces a new feature called #include cleanup, which aims to enhance productivity by improving code quality. This feature generates suggestions to remove unused headers and add direct headers, resulting in cleaner and better-organized code.
Remove Unused #include Statements
The #include cleanup feature provides suggestions to remove unused headers from your files, making your code cleaner. When an unused include is detected, it is visually dimmed by default. By hovering over the dimmed include, you can see a quick action prompt (indicated by three dots) that notifies you about the unused include in the file. Clicking on the light bulb icon allows you to remove the unused include or all unused includes, streamlining the code cleanup process.
Add Transitively Used #include Statements
Visual Studio already alerts users when an include is used but not added to the file. With the #include cleanup feature, you now have suggestions for adding direct includes when your file has indirect dependencies. By choosing to include all transitively used includes, direct headers will be automatically added wherever indirect headers are used in the file. After including the direct dependencies, it is important to remove any unused includes, keeping only the necessary ones for a clean codebase.
Configuring #include Cleanup
To enable the #include cleanup feature, navigate to Tools > Options > Text Editor > C/C++ > IntelliSense and select "Enable #include cleanup". You can also configure different levels and settings to meet your specific needs and preferences. For example, you can exclude certain files from the cleanup suggestions by adding their names to the cpp_include_cleanup_excluded_files option in the EditorConfig.
Your feedback on this feature is highly appreciated as it helps to further improve Visual Studio's functionality.