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?

16 Answers
16

Leave a Comment