Determine if Linux or Windows in C++

后端 未结 6 1873
忘了有多久
忘了有多久 2021-02-04 00:40

I am writing a cross-platform compatible function in C++ that creates directories based on input filenames. I need to know if the machine is Linux or windows and use the appropr

6条回答
  •  梦谈多话
    2021-02-04 00:59

    By default, Visual Studio #defines _WIN32 in the preprocessor project settings.

    So you can use

    // _WIN32 = we're in windows
    #ifdef _WIN32
    // Windows
    #else
    // Not windows
    #endif
    

提交回复
热议问题