且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

#include 和有什么区别?和#include“文件名"?

更新时间:2023-11-06 12:29:16

实际上,区别在于预处理器搜索包含文件的位置.

In practice, the difference is in the location where the preprocessor searches for the included file.

对于 #include ,预处理器以依赖于实现的方式搜索,通常在编译器/IDE 预先指定的搜索目录中.此方法通常用于包含标准库头文件.

For #include <filename> the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

对于 #include "filename",预处理器首先在包含指令的文件所在的目录中搜索,然后按照用于 #include 形式.此方法通常用于包含程序员定义的头文件.

For #include "filename" the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the #include <filename> form. This method is normally used to include programmer-defined header files.

在 GCC 关于搜索路径的文档中提供了更完整的描述.