【发布时间】:2012-04-24 02:51:08
【问题描述】:
是否存在任何 C++ 编译时宏来检测代码正在哪个 Windows 操作系统上编译。我基本上只想在Win7上支持某些功能。所以我有兴趣做这样的事情
#if <os_macro> = WIN7
// This function would do something valid only on Win7 builds.
bool myfunction {
// do something here
}
#else
// This function would typically return false, since its not supported on OS below win7
bool myfunction {
return false;
}
#endif
还有其他更好的方法吗?
【问题讨论】:
-
它在哪个操作系统上编译有什么帮助?它不需要知道它在哪个操作系统上运行吗?
-
在 Visual Studio 中,您可以使用
#ifdef WIN32或#ifdef _WINDOWS进行跨平台。如果您只想要 Windows 版本,您通常会自己定义WINVER。对于 Windows 7#define WINVER 0x0601
标签: c++ windows windows-7 header preprocessor-directive