从microsoft网站上找到关于#include Directive (C/C++)的相关问题解释如下:

The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears.

Syntax Form

Action

Quoted form

The preprocessor searches for include files in the following order:

  1. In the same directory as the file that contains the #include statement.

  2. In the directories of any previously opened include files in the reverse order in which they were opened. The search starts from the directory of the include file that was opened last and continues through the directory of the include file that was opened first.

  3. Along the path specified by each /I compiler option.

  4. Along the paths specified by the INCLUDE environment variable.

Angle-bracket form

The preprocessor searches for include files in the following order:

  1. Along the path specified by each /I compiler option.

  2. When compiling from the command line, along the paths that are specified by the INCLUDE environment variable.

按照上述,二者的区别在于:当被include的文件路径不是绝对路径的时候,有不同的搜索顺序。对于使用双引号“”包含的include文件,搜索的时候按以下顺序:

1.在包含当前include指令的文件所在的文件夹内搜索;

2.如果上一步找不到,则在之前已经使用include指令打开过的文件所在的文件夹内搜索,如果已经有多个被include的文件,则按照它们被打开的相反顺序去搜索;

3.如果上一步找不到,则在编译器设置的include路径内搜索;

4.如果上一步找不到,则在系统的INCLUDE环境变量内搜索。

而对于使用半角尖括号<>包含的include文件,搜索的时候按以下顺序:

1.在编译器设置的include路径内搜索;

2.如果是在命令行中编译,则在系统的INCLUDE环境变量内搜索。

对于非绝对路径的文件使用上述两种include指令搜索时,一旦找到include命令所指定的文件,编译器就停止搜索。但是如果被include的文件是绝对路径的文件,比如 #include "D:\Program Files\OpenCV1.0\cv\include\cv.h" ,被包含的cv.h文件路径是绝对路径,这种情况下编译器直接按照这个给出的绝对路径是搜索。

以下为一个使用尖括号<>include的例子:

#include <stdio.h>

在这个例子里,我们向源程序代码中包含stdio.h文件,由于使用的是尖括号<>,预处理器搜索的时候,先在编译器设置的include路径内搜索,如果找不到,就在系统的INCLUDE环境变量内搜索。

以下为一个使用双引号" "include的例子:

    #include "defs.h"
  在这个例子里,我们向源程序代码中包含defs.h文件,由于使用的是双引号" ",预处理器搜索的时候,使用了这条指令的父文件所在文件夹内搜索,所谓的父文件,就是这条include指令所在的文件,如果找不到,在父文件的父文件所在文件夹内搜索,如果仍然找不到,则在编译器设置的include路径内搜索,如果还找不到,就在系统的INCLUDE环境变量内搜索。

from:http://blog.csdn.net/godenlove007/article/details/7531521

include包含文件查找的顺序 .相关推荐

  1. 第五章:B视频Include包含文件

    今天给大家讲解一下Include包含文件 官网地址:https://www.w3soft.cn/codegenerator 视频教程如下 点我播放视频教程 操作代码 文件名: include生成文件 ...

  2. asp.net使用include包含文件中文乱码_C++: 编写自己的头文件

    C++的多文件结构和预编译命令入门课程,我觉得讲的很好: 学堂在线-国家精品课程在线学习平台​www.xuetangx.com 为在不同的文件中使用同一个类,类的定义就必须保持一致,为确保各个文件中类 ...

  3. PHP:include包含文件局部引入全局变量失效的作用域问题

    假设现有A B C三个PHP文件,B和C调用A,其中A.php的代码为: <?php /* 定义file:A.php, 假设当前目录为根目录 */// 定义全局变量: globalVariabl ...

  4. Quartus和Modelsim中使用`include包含头文件的对比

    在Quartus建立的工程中包含有头文件,而该工程在Modelsim仿真时有时会报错. Quartus版本是Quartus Prime 17.1 Lite Edition:Modelsim版本是Mod ...

  5. PHP中两种包含文件方式、三种注释风格、四种标记风格

    2019独角兽企业重金招聘Python工程师标准>>> 一.两种包含文件的方式 ①require语法格式:require("文件名"):这个函数通常放在PHP程序 ...

  6. Linux找头文件规则,linux 头文件、库文件查找顺序

    linux 头文件.库文件查找顺序 默认分类 2009-11-14 01:24:28 阅读126 评论0 字号:大中小 linux 头文件.库文件查找顺序 2009-11-03 12:36 Inclu ...

  7. 【转】C++中#include包含头文件带 .h 和不带 .h 的区别

    C++中#include包含头文件带 .h 和不带 .h 的区别? 如 #include <iostream> 和 #include <iostream.h> 包含的东西有哪些 ...

  8. php搜索所有路线,php包含文件路径查找规则

    首先,"路径"分为三种: 1.绝对路径,以/开头(unix系统)或c:等盘符开头(windows系统). 2.相对路径,以.开头,有./(当前目录)和../(上级目录). 3.其他 ...

  9. PHP包含文件函数include、include_once、require、require_once区别

    PHP的4个文件包含函数区别 include.include_once.require.require_once include() .require()语句包含并运行指定文件. 结构包含上基本一样, ...

  10. linux 中查找文件,并且将目标文件按时间顺序排序

    From: http://blog.csdn.net/linhx/article/details/5440288 linux 中,在redhat中检测过了,查找文件,并且将目标文件按时间顺序排序,这里 ...

最新文章

  1. 【Linux】 Linux简单操作之网络通信和网络访问
  2. 使用 Python 和 OpenCV 进行数据增广
  3. 有关C语言指针学习思想的随笔常用形式的总结(原创)
  4. MVC控件类型-HtmlHelper类
  5. 算法 求一个数组的最长递减子序列 C
  6. 我该建数仓、大数据平台还是数据中台?看完脑子终于清醒了
  7. Word中更新交叉引用
  8. PHP创建图像的应用!!!!
  9. Dojo-API介绍
  10. SP2中修复IE浏览器的一些技巧
  11. EasyUI:datagrid重置排序按钮状态
  12. jQuery炫酷特效之遮罩移动效果
  13. Matlab颜色RGB值
  14. SQL Server2005+SQL Server2000下载
  15. IFIX组态软件WINCC INTOUCH数据库 日志SQL记录,时班日报神器
  16. torch中dataloader加速
  17. IT公司面试智力题整理
  18. 《灵魂的微笑》读后感
  19. 三只小猪的故事[漫画]
  20. 叮咚,ps术语请查收~

热门文章

  1. jquery实现查看全部示例
  2. UOS设置屏幕缩放后的配置文件研究
  3. Could not initialize English chunker/Could not load file from classpath: ‘/en-token.bin‘
  4. relocation R_X86_64_PC32 against symbol ff_pw_9 can not be used when making a shared object
  5. 统信招5000人?难以置信
  6. 原因及解决办法:error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file
  7. 高手也不好当,压力更大
  8. JNI:需要显式指定使用jar的全路径
  9. 狐狸抓老鼠,为何东北向才会成功
  10. html代码不安全,安全 – HTML编码是否会阻止各种XSS攻击?