How to determine VS version of implementation method in the program

  • 2020-05-19 05:18:03
  • OfStack

The code is as follows:


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

In VC 6.0, the result is: 1200

In VC 10.0(VS2010), the result is: 1600

_MSC_VER is actually Microsoft visual c + + version (one of Microsoft's predefined macros).

The specific correspondence is as follows:

MS VC++ 14.0 _MSC_VER = 1900(VS2015)
MS VC++ 12.0 _MSC_VER = 1800(VS2013)
MS VC++ 11.0 _MSC_VER = 1700(VS2012)
MS VC++ 10.0 _MSC_VER = 1600(VS2010)
MS VC++ 9.0 _MSC_VER = 1500(VS2008)
MS VC++ 8.0 _MSC_VER = 1400(VS2005)
MS VC++ 7.1 _MSC_VER = 1310(VS2003)
MS VC++ 7.0 _MSC_VER = 1300
MS VC++ 6.0_MSC_VER = 1200
MS VC++ 5.0 _MSC_VER = 1100

So what does _MSC_VER do? Answer: version judgment, so as to achieve compatibility control.

Common usage:

#if _MSC_VER > = 1400 // for vc8, or vc9
#ifdef _DEBUG
#pragma comment( lib, "SomeLib-vc8-d.lib" )
#else if
#pragma comment( lib, "SomeLib-vc8-r.lib" )
#endif


Related articles: