< iostream>和“iostream” (引号)在#include? [英] Difference between <iostream> and "iostream" (quotes) in #include?
问题描述
可能重复:
#include< filename>之间的区别是什么?和#include“文件名
包括 #include< iostream>
的库。但也 #includeiostream
是正确的,代码将编译没有任何错误或问题。
所以,我想知道< >
和?
< >
,编译器仅查找系统指定的目录/目录(例如,您在 include
环境变量)。 当使用目录,如果失败,重新搜索就像你使用
< >
。从技术上讲,(即根据标准),不必是本地目录,但这是它如何工作在基本上每一个我知道的编译器)。
如果你关心,标准的官方措辞实际上是模糊的(§16.2/ 2-3):
的预处理指令
#include< h-char-sequence> new-line
搜索一系列实现定义的位置以查找由指定的
序列唯一标识的头,和>分隔符,并且导致该指令被头部的整个内容
替换。
的预处理指令
#includeq-char-sequencenew-line
导致该指令被整个内容由指定的
序列在分隔符之间标识的源文件的名称。以实现定义的
方式搜索指定的源文件。如果不支持此搜索,或者如果搜索失败,指令被重新处理,好像它读取
#include< h-char-sequence> new-line
Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?
When I written my programs, I include libraries like #include <iostream>
. but also #include "iostream"
is correct and the code would compiled without any error or problem.
So, I'm wondering what's the difference between < >
and " "
?
When you use < >
, the compiler only looks in the system-designated directory/directories (e.g., whatever you've set in the include
environment variable) for the header.
When you use " "
, the compiler looks in the local directory first, and if that fails, re-searches just like you'd used < >
. Technically, (i.e., according to the standard) that doesn't have to be the "local" directory, but that's how it works in essentially every compiler of which I'm aware).
In case you care, the official wording from the standard is actually kind of vague (§16.2/2-3):
A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
A preprocessing directive of the form
# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
# include <h-char-sequence> new-line
with the identical contained sequence (including > characters, if any) from the original directive.
这篇关于< iostream>和“iostream” (引号)在#include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!