Skip to content

Instantly share code, notes, and snippets.

@abranhe
Last active January 26, 2019 06:59
Show Gist options
  • Save abranhe/d9b43e7925a814447acafa2843dc80ba to your computer and use it in GitHub Desktop.
Save abranhe/d9b43e7925a814447acafa2843dc80ba to your computer and use it in GitHub Desktop.
Which Operating System are you using in C/C++?

Which Operating System are you using in C/C++?

I have created a module for this.

Installation

$ clib install abranhe/os.c
//
// Which os?
// https://repl.it/@abranhe/which-os
//
#include <iostream>
std::string getOsName()
{
#ifdef _WIN32
return "Windows 32-bit";
#elif _WIN64
return "Windows 64-bit";
#elif __unix || __unix__
return "Unix";
#elif __APPLE__ || __MACH__
return "Mac OSX";
#elif __linux__
return "Linux";
#elif __FreeBSD__
return "FreeBSD";
#else
return "Other";
#endif
}
int main() {
std::cout << "OS: " << getOsName() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment