Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Created November 17, 2020 15:16
Show Gist options
  • Save Adobe-Android/eff11494bb8580fa13145d89791b4a84 to your computer and use it in GitHub Desktop.
Save Adobe-Android/eff11494bb8580fa13145d89791b4a84 to your computer and use it in GitHub Desktop.
#include <iostream>
using std::cout;
using std::string;
int main() {
// Uses C++11 features.
string os{};
// Detect operating system.
#if defined(__linux__)
os = "Linux";
#if defined(__ANDROID__)
os = "Android";
#endif
#elif defined(_WIN32)
os = "Windows";
#elif defined(__APPLE__)
// Detect iOS before macOS (__MACH__ is also defined for iOS)
#if defined(IPHONE)
os = "iOS";
#elif defined(__MACH__)
os = "macOS";
#endif
#elif defined(__EMSCRIPTEN__)
os = "Emscripten";
#else
os = "Unable to determine operating system";
#endif
cout << os;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment