C++ - 包括 unistd.h:为什么不包括 cunistd?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15331566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ - include unistd.h: why not cunistd?
提问by CDT
It's said that when including C header files in C++, the ".h" suffix should be removed and then add "c" at the beginning. For example, #include <cstdio>
instead of #include <stdio.h>
. But when I use sleep()
in my code, #include <cunistd>
does not work, but #include <unistd.h>
works. Why not <cunistd>
?
据说在C++中包含C头文件时,应该去掉“.h”后缀,然后在开头加上“c”。例如,#include <cstdio>
代替#include <stdio.h>
. 但是当我sleep()
在我的代码中使用时,#include <cunistd>
不起作用,但#include <unistd.h>
有效。为什么不<cunistd>
呢?
回答by Carl Norum
Your algorithm is correct for most (all?) standard C headers, but unistd.h
is not part of standard C so standard C++ in turn doesn't include it with the other c...
headers.
您的算法对于大多数(所有?)标准 C 头文件都是正确的,但unistd.h
不是标准 C 的一部分,因此标准 C++ 反过来不将它与其他c...
头文件一起包含。
回答by comocomocomocomo
Because unistd.h
never was part of the C language. It is part of the Operating System.
因为unistd.h
从来就不是 C 语言的一部分。它是操作系统的一部分。
回答by Barath Ravikumar
<unistd.h>
, stands for unix standard header ,the name says it all.
<unistd.h>
, 代表 unix 标准头文件,名字说明了一切。
回答by babttz
unistd.h is not part of standard C. Standard C++ lib doesn't include it with the other c headers.
unistd.h 不是标准 C 的一部分。标准 C++ 库不包括它与其他 c 头文件。