#include <iostream>
#ifdef _WIN32
// Windows includes
#include <windows.h>
#else
// POSIX (Unix, Linux, macOS, etc.) includes
#include <unistd.h>
#include <sys/utsname.h>
#endif
int main()
{
#ifdef _WIN32
// Windows-specific code
OSVERSIONINFOEX osvi;
SYSTEM_INFO si;
BOOL bOsVersionInfoEx;
ZeroMemory(&si, sizeof(SYSTEM_INFO));
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*)&osvi);
if (!bOsVersionInfoEx) {
std::cerr << "Failed to get OS version information." << std::endl;
return 1;
}
GetSystemInfo(&si);
std::cout << "Current C++ Standard: " << __cplusplus << std::endl;
std::cout << "Operating system: " << "Windows" << std::endl;
std::cout << "Major version: " << osvi.dwMajorVersion << std::endl;
std::cout << "Minor version: " << osvi.dwMinorVersion << std::endl;
std::cout << "Build number: " << osvi.dwBuildNumber << std::endl;
std::cout << "Platform: " << osvi.dwPlatformId << std::endl;
std::cout << "Service pack: "
<< (osvi.szCSDVersion[0] ? osvi.szCSDVersion : "None")
<< std::endl;
switch (si.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
std::cout << "Machine: AMD64" << std::endl;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
std::cout << "Machine: x86" << std::endl;
break;
case PROCESSOR_ARCHITECTURE_ARM:
std::cout << "Machine: ARM" << std::endl;
break;
case PROCESSOR_ARCHITECTURE_IA64:
std::cout << "Machine: IA64" << std::endl;
break;
case PROCESSOR_ARCHITECTURE_ARM64:
std::cout << "Machine: ARM64" << std::endl;
break;
default:
std::cout << "Machine: Unknown architecture" << std::endl;
break;
}
#else
// Unix/POSIX-specific code
struct utsname unameData;
if (uname(&unameData) != 0) {
std::cerr << "Failed to get system information." << std::endl;
return 1;
}
std::cout << "Current C++ Standard: " << __cplusplus << std::endl;
std::cout << "Operating system: " << unameData.sysname << std::endl;
std::cout << "Node name: " << unameData.nodename << std::endl;
std::cout << "Release: " << unameData.release << std::endl;
std::cout << "Version: " << unameData.version << std::endl;
std::cout << "Machine: " << unameData.machine << std::endl;
#endif
return 0;
}