相关疑难解决方法(0)

基于操作系统的C++条件编译

我想用C++编写一个包含系统调用的跨平台函数.我可以检查哪些条件编译标志来确定编译代码的操作系统是什么?我主要对Windows和Linux感兴趣,使用Visual Studio和GCC.

我认为应该看起来像这样:

void SomeClass::SomeFunction()
{
    // Other code

#ifdef LINUX
    LinuxSystemCall();
#endif

#ifdef WINDOWS
    WindowsSystemCall();
#endif

    // Other code
}
Run Code Online (Sandbox Code Playgroud)

linux windows cross-platform conditional-compilation visual-studio

6
推荐指数
3
解决办法
8138
查看次数