C语言中,#include的用法:#include "" 和 #include<>区别

采用 " ":依次搜索当前目录、包括/I编译开关的路径、包括INCLUDE环境变量的路径  
采用<>:依次搜索包括/I编译开关的路径、包括INCLUDE环境变量的路径

The #include Directive
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. You can organize constant and macro definitions into include files and then use #include directives to add these definitions to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. You only need to define and name the types once in an include file created for that purpose.

Syntax

#include "path-spec"

#include <path-spec>

The path-spec is a filename optionally preceded by a directory specification. The filename must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled.

Both syntax forms cause replacement of that directive by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified.

Syntax Form Action 
Quoted form This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of whatever files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable. 
Angle-bracket form This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then along the path specified by the INCLUDE environment variable.

The preprocessor stops searching as soon as it finds a file with the given name. If you specify a complete, unambiguous path specification for the include file between two sets of double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories.

If the filename enclosed in double quotation marks is an incomplete path specification, the preprocessor first searches the “parent” file’s directory. A parent file is the file containing the #include directive. For example, if you include a file named file2 within a file named file1, file1 is the parent file.

Include files can be “nested”; that is, an #include directive can appear in a file named by another #include directive. For example, file2, above, could include file3. In this case, file1 would still be the parent of file2 but would be the “grandparent” of file3.

When include files are nested, directory searching begins with the directories of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source currently being processed. If the file is not found, the search moves to directories specified by the /I compiler option. Finally, the directories specified by the INCLUDE environment variable are searched.

The following example shows file inclusion using angle brackets:

#include <stdio.h>

This example adds the contents of the file named STDIO.H to the source program. The angle brackets cause the preprocessor to search the directories specified by the INCLUDE environment variable for STDIO.H, after searching directories specified by the /I compiler option.

The following example shows file inclusion using the quoted form:

#include "defs.h"

This example adds the contents of the file specified by DEFS.H to the source program. The double quotation marks mean that the preprocessor searches the directory containing the parent source file first.

Nesting of include files can continue up to 10 levels. Once the nested #include is processed, the preprocessor continues to insert the enclosing include file into the original source file.

Microsoft Specific

To locate includable source files, the preprocessor first searches the directories specified by the /I compiler option. If the /I option is not present or fails, the preprocessor uses the INCLUDE environment variable to find any include files within angle brackets. The INCLUDE environment variable and /I compiler option can contain multiple paths separated by semicolons (;). If more than one directory appears as part of the /I option or within the INCLUDE environment variable, the preprocessor searches them in the order in which they appear.

For example, the command

CL /ID:\MSVC\INCLUDE MYPROG.C

causes the preprocessor to search the directory D:\MSVC\INCLUDE for include files such as STDIO.H. The commands

SET INCLUDE=D:\MSVC\INCLUDE
CL MYPROG.C

have the same effect. If both sets of searches fail, a fatal compiler error is generated.

If the filename is fully specified for an include file with a path that includes a colon (for example, F:\MSVC\SPECIAL\INCL\TEST.H), the preprocessor follows the path.

For include files specified as #include "path-spec", directory searching begins with the directory of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source file containing the #include directive being processed. If there is no grandparent file and the file has not been found, the search continues as if the filename were enclosed in angle brackets.

END Microsoft Specific

C语言中,#include的用法:#include 和 #include区别相关推荐

  1. c语言 fread读指定字节,c语言中fread的用法

    fread是以记录为单位的I/O函数,fread和fwrite函数一般用于二进制文件的输入输出.下面小编就跟你们详细介绍下c语言中fread的用法,希望对你们有用. c语言中fread的用法如下: # ...

  2. c语言eof不起作用,c语言中EOF的用法

    c语言中EOF的用法以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! c语言中EOF的用法 1.EOF是end of fi ...

  3. c语言中getche的用法,c语言中getch的用法

    [www.hywsbj.com--图表展板] getch()函数是无回显的从控制台取得一个字符.以利用getch()函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面,即任意键继续效果.下面小编 ...

  4. c语言中size of 用法,C语言中sizeof()的用法

    要参加软件研发的笔试(C/C++)几乎都会涉及到sizeof()的用法,我昨天也遇到了,有的也会,但是真正sizeof()的核心还是没有领会,今天上网,无聊中就看到了详细的sizeof()的阐述,现在 ...

  5. #define c# 报错_c语言中#define的用法

    c语言中#define的用法 C语言中,可以用 #define 定义一个标识符来表示一个常量.其特点是:定义的标识符不占内存,只是一个临时的符号,预编译后这个符号就不存在了. 预编译又叫预处理.预编译 ...

  6. getch方法_c语言中getch的用法

    1 c 语言中 getch 的用法 getch() 函数是无回显的从控制台取得一个字符. 以利用 getch() 函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面 , 即 任意键继续效果.下面 ...

  7. map函数作用c语言,c语言中map的用法:map基本用法

    c++中map容器提供一个键值对容器,那么你知道map的用法有哪些吗,下面秋天网 Qiutian.ZqNF.Com小编就跟你们详细介绍下c语言中map的用法,希望对你们有用. c语言中map的用法:m ...

  8. c语言define需要分号骂,C语言中define的用法

    C语言中define的用法 2016-01-06 15:00  来源: 博客园 define是C语言中的预处理命令,它用于宏定义,可以提高源代码的可读性,为编程提供方便. 预处理命令以"#& ...

  9. c语言控制字符的作用是什么意思,c语言中char的用法是什么意思

    C语言是计算机软件领域非常经典的编程语言,C语言中char的作用有哪些你了解吗.下面学习啦小编就跟你们详细介绍下c语言中char的用法,希望对你们有用. c语言中char的用法:c语言中char的用法 ...

  10. c语言int作用,c语言中int的用法有哪些

    c语言中int的用法有哪些 C/C++编程语言中,int表示整型变量,是一种数据类型,用于定义一个整型变量,在不同编译环境有不同的大小,不同编译运行环境大小不同下面小编给大家整理了c语言中int的用法 ...

最新文章

  1. jwt token长度限制_ASP.NET Core Web Api之JWT(一)
  2. Reactor构架模式--转载
  3. 1.3 Error和Exception的异同
  4. k8s kubectl run命令使用详解
  5. 【easyui】treegrid逐级加载源码
  6. 10 分钟快速入门海量数据搜索分析引擎 Elasticearch
  7. sqlsever2008数据库的备份与还原
  8. instanceof的用法①
  9. 【转】Android加密算法:AES、Base64加密算法
  10. linux配置端口ipv6地址,linux配置ipv6地址命令
  11. javadoc 程序包android.content不存在,Eclipse中的Javadoc无法识别包
  12. 2叉树排序缺失元素查找
  13. (百万数据量级别)java下的mysql数据库插入越插越慢的问题解决
  14. 某学院软件工程复试回忆总结
  15. android开源音乐播放器简单demo,Android开源在线音乐播放器——波尼音乐
  16. (扒站工具)如何下载网站fonts文件夹
  17. 计算机绘图课程选用课本,机械制图课程学习指南.doc
  18. python实现基于selenium的天猫淘宝秒杀,支持定金商品,自动付款
  19. oracle net Manager 配置连接 tiptop 鼎捷ERP 数据库
  20. plsql导出文件转mysql_PLSQL Developer导入导出数据库

热门文章

  1. 03 ,似然函数求解 :目标函数推导,对数似然求解,最小二乘法
  2. 三态内容寻址存储器(TCAM)工作原理
  3. CF1151F Sonya and Informatics
  4. 5240: C++实验:矩形面积
  5. AI测试】人工智能测试整体介绍——第五部分
  6. 如何提高接口自动化测试的有效性覆盖和案例有效性
  7. vue3源码系列之计算属性computed原理剖析
  8. linux如何把文件大小改为0,关于文件系统:Linux删除大小为0的文件
  9. 利用python绘制雪景图_彩铅 · 教程 | 教你画一张唯美雪景小图
  10. CSS中英文换行问题