Get MSVC Compiler Version Used to Compile C++ Code

Get MSVC Compiler Version Used to Compile C++ Code

When working with Microsoft Visual C++ (MSVC) compiler, it could be helpful to know exactly which compiler version is being used - especially when debugging, managing dependencies, or writing conditional code for specific toolsets. This tutorial shows how to get MSVC compiler version used to compile C++ code.

The _MSC_VER macro is defined by the MSVC compiler and represents the major and minor version of the compiler in the format MMNN. The following code will output the compiler version:

#include <iostream>
 
int main()
{
    std::cout << _MSC_VER << std::endl;
 
    return 0;
}

Example output:

1940

This value corresponds to MSVC version 19.40, which is associated with Visual Studio 2022 version 17.10. These version numbers are often used when checking for compatibility or implementing compiler-specific workarounds.

Leave a Comment

Cancel reply

Your email address will not be published.