如何检测操作系统 [英] how to detect OS
本文介绍了如何检测操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c / c ++检测正在运行的操作系统,以便我们可以制作便携式代码....
例如:
#include< windows.h>
代码...
睡眠(200);
代码..
ths适用于windows ...
-------------- -------------------------------------------
>
#include< unistd.h>
代码...
sleep(2);
代码...
$ b $用于uni系统
现在我们如何制作一个可移植的代码使用适当的版本取决于操作系统...
how to detect which operating system is running using c/c++ so tht we can make portable codes....
for example:
#include <windows.h>
code...
Sleep(200);
code..
ths is for windows...
---------------------------------------------------------
# include <unistd.h>
code...
sleep(2);
code...
ths for uni system
now how can we make a portable code tht uses appropriate version depending on the OS...
推荐答案
用于编写可移植代码的常用方法是这样的
Hi,
The common approach used to write Portable code is like this
展开 | 选择 | Wrap | 行号
和当然你把你的调用放在一个包装函数中睡眠/睡眠,所以你只需要在代码中的#ifdef ...构造一个
And of course you put your call to sleep/Sleep inside a wrapper function so you only have to have the #ifdef ... construct in 1 place in the code
,但我的编译器如何检测OS .....即说如何检测操作系统...如果我检测到一个,那么你说我就是这么做....
but how would my compiler detect OS.....i.e to say how to detect OS...wat u said is what i shd do if i detect one....
这篇关于如何检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文