How do I check OS with a preprocessor directive?
问题 I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 回答1: The Predefined Macros for OS site has a very complete list of checks. Here are a few of them, with links to where they're found: Windows _WIN32 Both 32 bit and 64 bit _WIN64 64 bit only Unix (Linux,