我正在尝试编写一个识别当前 Windows 版本的 C++ 程序。我看到了几十个这样的问题和答案,但没有一个对我有用。
我正在运行 Windows 10 家庭版。
我正在使用 Visual Studio 2015。
我尝试过的第一个选项:
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
cout << osvi.dwMajorVersion << endl;
cout << osvi.dwMinorVersion << endl;
这将打印 6 和 2 根据MSDN对应于 Windows 8。
我尝试过的第二种选择:
#include <VersionHelpers.h>
if (IsWindowsVistaOrGreater())
printf("VistaOrGreater\n");
if (IsWindows7OrGreater())
printf("Windows7OrGreater\n");
if (IsWindows8OrGreater())
printf("Windows8OrGreater\n");
if (IsWindows8Point1OrGreater())
printf("Windows8Point1OrGreater\n");
if (IsWindows10OrGreater())
printf("Windows10OrGreater\n");
这样,我的系统中没有定义IsWindows10OrGreater()并给出编译错误。
有什么帮助吗?