visual studio c++ 不同 版本 定义 宏
//z 2013-01-28 10:19:58 IS2120@BG57IV3.T3314393399.K[T82,L1217,R37,V1207]
_MSC_VER
is what you need. You can also examine visualc.hpp in any recent boost install for some usage examples.

Some values for the more recent versions of the compiler are:

MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2012)
MSVC++ 10.0 _MSC_VER = 1600 (Visual Studio 2010)
MSVC++ 9.0  _MSC_VER = 1500 (Visual Studio 2008)
MSVC++ 8.0  _MSC_VER = 1400 (Visual Studio 2005)
MSVC++ 7.1  _MSC_VER = 1310 (Visual Studio 2003)
MSVC++ 7.0  _MSC_VER = 1300
MSVC++ 6.0  _MSC_VER = 1200
MSVC++ 5.0  _MSC_VER = 1100

The version number above of course refers to the major version of your Visual studio you see in the about box, not to the year in the name.


cl.exe /? will give a hint of the used version


//z 2013-01-28 10:19:58 IS2120@BG57IV3.T3314393399.K[T82,L1217,R37,V1207]


使用时的例子:


#if (_MSC_VER >= 1500 && _MSC_VER < 1600)
   // ... Do VC9/Visual Studio 2008 specific stuff
#endif