Επεξεργασία

Κοινή χρήση μέσω


Include Cleanup messages

This article describes the messages generated by the Include Cleanup feature. For more information about Include Cleanup, see C/C++ Include Cleanup overview.

Starting with 17.8 Preview 1, Visual Studio can clean up your #includes to improve the quality of your C and C++ code in the following ways:

  • Offers to add header files for code that compiles only because a needed header file is included indirectly by another header file.
  • Offers to remove unused header files--improving build times.

You can choose whether messages from Include Cleanup appear in the form of suggestions, warnings, or errors in the Error List window. For more information, see Config C/C++ Include Cleanup in Visual Studio.

In the following screenshot of the Error List, Include Cleanup is configured to show unused headers with a warning:

A screenshot of the Error List window.

The dropdown filter is set to Build + IntelliSense. A warning is visible: VCIC002 - #include < iostream > isn't used in this file."

Include Cleanup generates the following messages:

VCIC001: Content from #include is used in this file and transitively included

This message means that you're using content from a header file that is included indirectly.

For example, you may be directly including a header file that also contains #include <string>. If you use string in your code, but don't #include <string> in that file, it works as long as the other header file continues to indirectly include <string> for you. This message identifies this situation in your code so that you can take action to directly include the transitively included header file. For more information, see Direct vs indirect headers.

VCIC002: #include is not used in this file

This message means that the specified header file is not used in the current file. You can remove the associated #include directive to clean up your #includes and improve your build times.

See also

C/C++ Include Cleanup overview
Configure C/C++ Include Cleanup in Visual Studio