2015/02/10

C++ 判斷作業系統

Code:
#include <stdio.h>
#include <stdlib.h>

int main(){
printf("Your system is ");
#ifdef __WINDOWS__
        printf("Windows");
        #ifdef __WIN64
                printf("64\n");
        #elif
                printf("32\n");
        #endif
#elif __APPLE__
        printf("Apple\n");
#elif _unix
        printf("UNIX\n");
#elif _linux
        printf("Linux");
#endif

return 0;
}




參考資料:
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
http://sourceforge.net/p/predef/wiki/OperatingSystems/

沒有留言:

張貼留言