_MSC_VER is a pre-processor macro. It will expand when you
compile your program. And it will expand to whatever version of MSVC
you have been using to compile the program. Consequently, reading this value
at runtime, on a user's machine, will tell you absolutely
nothing about what compiler (or C++ Runtime) is installed
there! It is simply a
constant value in your compiled program.
But why do you want to detect the
compiler version on the user's machine? Users usually do
not have a compiler installed at all! So maybe what you actually want is to detect which version of the C++
Runtime libraries is installed? Or are you shipping
source files to be compiled on the user's machine? If so, it would be very unusual and you should be shipping the compiled program ("EXE file") instead.
In case you really which to detect the
compiler version, e.g. because you are distributing a piece of software that is intended to be used by
software developers, just run the
cl.exe that is installed on the user's machine. Then parse the version string...
D:\Microsoft Visual Studio 11.0\VC>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Either that, or read the installed Visual Studio version from the registry 😉