2016-10-12 116 views
-1

我想編寫一個C++程序,標識當前的Windows版本。 我看到了許多這樣的問題和答案,但他們都沒有爲我工作。與Windows 10家庭C++ Windows版本問題

我正在運行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()沒有在我的系統中定義,並給出編譯錯誤。

對此有何幫助?

回答

2

在Windows 8.1和Windows 10中,GetVersion和GetVersionEx函數已被棄用。不適用於Windows 8.1或Windows 10的應用程序將返回Windows 8操作系統版本值(6.2)

有關更多信息,請參閱Targeting your application for Windows

+0

那麼對於Windows 10來說唯一的辦法就是通過這個體現? – mbaros

+1

@mbaros顯然不是。鏈接的問題有一個非常聰明的解決方案,你可以嘗試。 – jhbh

+0

是的。我已經看到了。謝謝 – mbaros

相關問題