How can I detect if the operating system is Windows in C++/C?
#ifdef _WIN32
cout << "This is Windows." << endl;
#endif
This will allow you define blocks for windows only. As long as the preprocessor macro is defined.
This is a compile time thing, not a runtime thing.
You can use getenv()
from cstdlib like so:
#include <cstdlib>
getenv("windir");
If you get NULL
then it's not windows.
This works since %windir%
should only be defined on windows systems. This is a cheap and dirty hack of course.
http://www.cplusplus.com/reference/clibrary/cstdlib/getenv/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With