有没有办法通过C/C++代码自动检测您的操作系统?我需要为Linux、Windows甚至树莓派运行一些跨平台代码。我正在尝试自动检测操作系统,以便不必询问机器上运行的操作系统作为输入。
我在想像验证文件系统结构之类的黑客攻击,但我不知道是否正确。
我在想像验证文件系统结构之类的黑客攻击,但我不知道是否正确。
我过去使用过以下代码来检查Linux和Windows之间的差异
#include<stdio.h>
int main(int argc, char *argv[])
{
#ifdef _WIN32
printf("in Windows");
#endif
#ifdef linux
printf("In Linux");
#endif
return 0;
}
http://sourceforge.net/p/predef/wiki/OperatingSystems/
System.getProperty("os.name")
同样的,在C/C++中我们没有任何API。
uname
。 - Basile Starynkevitch