How to suppress warnings in external headers in Visual C++

Use this method around (a) header(s) that you cannot or don’t want to change, but which you need to include.

You can selectively, and temporarily disable all warnings like this:

#pragma warning(push, 0)
// Some include(s) with unfixable warnings
#pragma warning(pop)

Instead of 0 you can optionally pass in the warning number to disable, so something like:

#pragma warning(push)
#pragma warning(disable : 4081)
#pragma warning(disable : 4706)
// Some code
#pragma warning(pop)

Leave a Comment