#include<file.h>与#include"file.h"的区别

简介:
对于这种问题先来看一看外国人怎么想的,因为本来这种语言就是他们创造的,http://www.geekinterview.com/question_details/3379
 
 
What is the difference between #include <file> and #include “file”?
When writing your C program, you can include files in two ways. The first way is to surround the file you want to include with the angled brackets < and >. This method of inclusion tells the preprocessor to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable
INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;
using the #include <file> version of file inclusion, the compiler first checks the C:COMPILERINCLUDE
directory for the specified file. If the file is not found there, the compiler then checks the
S:SOURCEHEADERS directory. If the file is still not found, the preprocessor checks the current directory.
 
The second way to include files is to surround the file you want to include with double quotation marks. This
method of inclusion tells the preprocessor to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include “file” version of file inclusion and applying
it to the preceding example, the preprocessor first checks the current directory for the specified file. If the
file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file
is still not found, the preprocessor checks the S:SOURCEHEADERS directory.
The #include <file> method of file inclusion is often used to include standard headers such as stdio.h or
stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your
compiler’s standard include file directory. 
The #include “file” method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the preprocessor to use your newly modified version of the header rather than the older, unmodified version.
 
 
 
总的来说:
当用#include“file.h”时,先搜索当前工作目录,如果没有,再去搜索库,库没有再搜索资源库;
当用#include<file.h>时,编译器先从标准库路径开始搜索,如果没再搜索资源库目录,最好搜索当前工作目录。
相关文章
|
监控 安全 物联网
Wi-Fi 简史(802.11a 到 802.11ax)
【4月更文挑战第15天】
3518 2
Wi-Fi 简史(802.11a 到 802.11ax)
|
5月前
|
Linux 程序员 API
CentOS如何使用Pthread线程库
这就是在CentOS下使用Pthread线程库的全过程。可见,即使是复杂的并发编程,只要掌握了基本的知识与工具,就能够游刃有余。让我们积极拥抱并发编程的魅力,编写出高效且健壮的代码吧!
103 11
|
机器人 测试技术 C++
ModbusCRC16校验 示例代码
本文提供了ModbusCRC16校验的示例代码,包括计算CRC、添加CRC校验位、删除CRC校验位和比较CRC校验位等四种常用函数的实现,以及一个完整的示例代码。这些代码在Ubuntu20.04环境下经过测试并确认有效。示例代码采用C++编写,展示了如何使用这些函数来处理Modbus通信中的数据校验。
654 2
`cmd`模块是Python标准库中的一个模块,它提供了一个简单的框架来创建命令行解释器。
`cmd`模块是Python标准库中的一个模块,它提供了一个简单的框架来创建命令行解释器。
|
物联网 5G SDN
5G 网络架构全解析:RAN、核心网和接入网
5G 网络架构全解析:RAN、核心网和接入网
3050 8
|
存储 缓存 算法
LabVIEW大量数据的内存管理
LabVIEW大量数据的内存管理
312 1
|
消息中间件 存储 缓存
|
存储 数据可视化
Fama French (FF) 三因子模型和CAPM模型分析股票市场投资组合风险/收益可视化
Fama French (FF) 三因子模型和CAPM模型分析股票市场投资组合风险/收益可视化
Fama French (FF) 三因子模型和CAPM模型分析股票市场投资组合风险/收益可视化
|
编译器 C语言 C++
VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统---保姆级教程
VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统---保姆级教程
9559 0
|
安全 5G 测试技术
5G的要求和主要性能指标 | 《5G移动无线通信技术》之六
这里对前面章节所述用例的要求加以总结,表达了5G主要性能指标(KPI)。
5G的要求和主要性能指标 | 《5G移动无线通信技术》之六