C语言 <stdio.h> 和“stdio.h”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3845415/
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
What is the difference between <stdio.h> and "stdio.h"?
提问by Parikshita
Possible Duplicate:
what is the difference between #include <filename> and #include “filename”
In both cases there is no error ...Is there any difference between them ?
在这两种情况下都没有错误......它们之间有什么区别吗?
回答by Alan Haggai Alavi
<stdio.h>searches in standard C library locations, whereas "stdio.h"searches in the current directory as well.
<stdio.h>在标准 C 库位置中"stdio.h"搜索,同时也在当前目录中搜索。
Ideally, you would use <...>for standard C libraries and "..."for libraries that you write and are present in the current directory.
理想情况下,您将<...>用于标准 C 库和"..."您编写并存在于当前目录中的库。
回答by Johannes Schaub - litb
The second version is specified to search first in an implementation defined location, and afterwards if the file is not found, search in the same place as the <...>version, which searches in the paths usually specified by the -Icommand line option and by built-in include paths (pointing to the location of the standard library and system headers).
指定第二个版本首先在实现定义的位置搜索,然后如果找不到文件,则在与<...>版本相同的位置搜索,通常在-I命令行选项和内置include指定的路径中搜索路径(指向标准库和系统头文件的位置)。
Usually, implementations define that location to be relative to the location of the including file.
通常,实现定义该位置相对于包含文件的位置。
回答by Lie Ryan
You use #include when you want to say: "look for a file with this name in the system's include directory". You use #include "doublequoted" when you want to say: "look for a file with this name in my own application's include directory; however, if it can't be found, look in the system's include directory".
当您想说:“在系统的包含目录中查找具有此名称的文件”时,您可以使用 #include。当您想说:“在我自己的应用程序的包含目录中查找具有此名称的文件;但是,如果找不到,请在系统的包含目录中查找”时,您可以使用 #include "doublequoted"。
回答by Venemo
The <> tell the compiler to look for the file in the libraries' headers and "" tell it to look around among your application's headers.
<> 告诉编译器在库的头文件中查找文件,而 "" 告诉它在应用程序的头文件中四处寻找。
As for why both of them works for you, maybe your compiler also looks for the filename in the library headers in case it didn't find one among yours.
至于为什么它们都适合你,也许你的编译器也在库头文件中查找文件名,以防它在你的文件中找不到。
回答by Abhi
I case of "..."compiler first search the header file in your local directory where
your .c file presents
我的"..."编译器首先在你的.c文件所在的本地目录中搜索头文件
while in case of <...>compiler only search in header file folder
而在<...>编译器的情况下只在头文件文件夹中搜索
回答by che
#include <something.h>is meant for system headers, while #include "something.h"is for headers of your own program. System headers are searched for in usual system directories (and those included with -Iargument), which your headers are searched for in current directory and then the same locations as system headers.
#include <something.h>用于系统头文件,而#include "something.h"用于您自己程序的头文件。在通常的系统目录(以及包含在-I参数中的目录)中搜索系统标头,在当前目录中搜索您的标头,然后在与系统标头相同的位置搜索。
see http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC6
回答by John Percival Hackworth
For the compilers I've used, "..." starts looking for the include file in the same directory as the source file that is being compiled, then the include path. Includes with <...> start in the include path, skipping the current die unless it is in the include path.
对于我使用过的编译器,“...”开始在与正在编译的源文件相同的目录中查找包含文件,然后是包含路径。在包含路径中以 <...> 开头的包含,跳过当前模具,除非它在包含路径中。
回答by ArK
Normally standard header files are enclosed by < > and other user specific files are specifed with " .
通常标准头文件用 < > 括起来,其他用户特定的文件用“.
回答by pmg
<stdio.h>refers to a header (not a header file)"stdio.h"refers to a source file.
<stdio.h>指头文件(不是头文件)"stdio.h"指的是源文件。
Headers need not exist phisically in the implementation; the way they are identified is implementation-defined (usually the headers are files on specific directories)
头文件在实现中不需要物理存在;它们的识别方式是实现定义的(通常头文件是特定目录中的文件)
When the directive uses ", the source file is searched in an implementation-defined manner and, if not found, the directive is reprocessed as if it was written with <and >in the first place.
当指令使用 时",以实现定义的方式搜索源文件,如果未找到,则重新处理指令,就像它最初是用<和编写的一样>。
回答by cateof
The difference is that header files made by the developer are enclosed by "". Header files that are already in the system are enclosed with <>. Even the <> headers need the -I directive if the directories that are placed are not in the search path of the compiler.
不同的是开发者制作的头文件用“”括起来。系统中已有的头文件用 <> 括起来。如果放置的目录不在编译器的搜索路径中,即使 <> 标头也需要 -I 指令。
Bottom line: Your headers with "", system headers with <>
底线:带有“”的标题,带有 <> 的系统标题

