一个可以识别并返回系统类型的程序

如下,取 _SYSTEM_ 的值即可。

#include <iostream>
#include <cstdlib>
#include <string>
const int N = 100;
using namespace std;
// system check
#if defined(_WIN32)
	#define _SYSTEM_ 1  // Windows
	#include<windows.h>
#elif defined(__ANDROID__)
	#define _SYSTEM_ 5  // Android
#elif defined(__APPLE__)
	#include <TargetConditionals.h>
	#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
		#define _SYSTEM_ 6  // iOS
	#else
		#define _SYSTEM_ 4  // macOS
		#include <termios.h>
		#include <unistd.h>
	#endif
#elif defined(__linux__)
	#define _SYSTEM_ 2  // Linux
	#include <termios.h>
	#include <unistd.h>
#elif defined(__unix__)
	#define _SYSTEM_ 3  // Other Unix (except Apple,Linux&Android)
	#include <termios.h>
	#include <unistd.h>
#endif
/*
System list

type		code
Windows		1
Linux		2
Other Unix	3
MacOS		4
Android		5
IOS			6

Get code from "_SYSTEM_"
*/
1 个赞

在Linux环境下测试可以编译运行。
系统 debian
内核 5.4.18-85-generic