两种include的区别

 #include< >和#include“”的区别

< >引用的是编译器的类库路径里面的头文件

" "引用的是程序目录的相对路径中的头文件


作者:暮无井见铃

链接:https://www.zhihu.com/question/25436617/answer/202700196

来源:知乎

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

从标准来看

n4659, 19.2 Source file inclusion, 2

A preprocessing directive of the form

# include < h-char-sequence >

searches a sequence of implementation-defined places for a headeridentified uniquely by the specified sequence between the < and >delimiters, and causes the replacement of that directive by the entire contentsof the header. How the places are specified or the header identified isimplementation-defined.


拥有此形式的预处理指令

# include < h-char-sequence >

于一序列实现定义位置,查找由 < 与 > 分隔符之间的序列所唯一标识的头文件,并导致该指令为头文件的整体内容所替换。位置如何指定,或头文件如何标识,是实现定义的。


n4659, 19.2 Source file inclusion, 3

A preprocessing directive of the form

# include " q-char-sequence "

causes the replacement of that directive by the entire contents ofthe source file identified by the specified sequence between the "delimiters. The named source file is searched for in an implementation-definedmanner. If this search is not supported, or if the search fails, the directiveis reprocessed as if it read

# include < h-char-sequence >

with the identical contained sequence (including > characters, ifany) from the original directive.


拥有此形式的预处理指令

# include " q-char-sequence "

导致该指令为 " 分隔符间的序列所标识的源文件的整体内容所替换。指名的源文件以实现定义行为查找。若不支持此查找,或若查找失败,则此指令以如同它从原指令,以相同的所含序列读取

# include < h-char-sequence >(包含 > 字符,若它存在)。


(C11 标准里也有一模一样的话)

简言之 #include <> 和 #include "" 都会在实现定义的位置查找文件,并将其包含。

区别是若 #include "" 查找成功,则遮蔽 #include <> 所能找到的同名文件;否则再按照 #include<> 的方式查找文件。另外标准库头文件都放在 #include <> 所查找的位置。

一般来说 #include <> 的查找位置是标准库头文件所在目录, #include "" 的查找位置是当前源文件所在目录。不过这些都可由编译器调用参数等配置更改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值