C头文件中尖括号与双引号的区别

2.1 Include Syntax

Both user and system header files are included using the preprocessing directive ‘#include’. It has two variants:

#include <file>

This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option.

The argument of ‘#include’, whether delimited with quote marks or angle brackets, behaves like a string constant in that comments are not recognized, and macro names are not expanded. Thus, #include <x/*y> specifies inclusion of a system header file named x/*y.

However, if backslashes occur within file, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed. Thus, #include "x\n\\y" specifies a filename containing three backslashes. (Some systems interpret ‘\’ as a pathname separator. All of these also interpret ‘/’ the same way. It is most portable to use only ‘/’.)

It is an error if there is anything (other than comments) on the line after the file name.

摘抄自 https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html#Include-Syntax

简单理解就是:

1. 尖括号告诉编译器去搜索系统目录,可使用 -I 选项添加其它搜索目录

2. 双引号告诉编译器先搜索源文件所在目录,其次搜索引号内的目录,最后搜索系统目录, -iquote 选项可添加其它目录到引号目录列表中。

原文地址:https://www.cnblogs.com/miaoxiong/p/10938136.html

时间: 2024-08-09 10:26:10

C头文件中尖括号与双引号的区别的相关文章

C++包含头文件时尖括号和双引号区别

原文链接:http://c.biancheng.net/cpp/biancheng/view/66.html 如果你还看一些别的C++教程,那么你可能很早就发现了,有些书上的#include命令写作#include <文件名>,但有时候又会出现#include "文件名".你会很疑惑,到底哪个是对的呢?为什么要有这两种不同的写法呢? 这两种写法都是正确的写法,但是它们却是有区别的.我们知道C++已经有一些编写好的头文件(比如标准函数库等等),它们存放在VC++的Includ

转载 关于include尖括号和双引号的区别。

对于使用尖括号( < >),预处理程序cpp在系统预设包含文件目录(如/usr/include)中搜寻相应的文件,而对于使用双引号(“ ”),cpp在当前目录中搜寻头文件,这个选项的作用是告诉cpp,如果在当前目录中没有找到需要的文件,就到指定的dirname目录中去寻找.在程序设计中,如果我们需要的这种包含文件分别分布在不同的目录中,就需要逐个使用-I选项给出搜索路径. 通常用 < >包含的是标准库的头文件,而用""包含的是用户自己定义的类库的头文件.&quo

C++中#include &lt;xxx.h&gt;和#include &quot;xxx.h&quot;的区别(尖括号和双引号的区别)

第一种方式:采用< >方式,表示让编译器在编译器的预设标准路径下去搜索相应的头文件,如果找不到则报错. 例如:VS2015的安装目录\Microsoft Visual Studio 14.0\VC\include下面就包含了标准库的头文件. 第二种方式:采用" "方式,表示先在工程所在路径下搜索,如果失败,再到系统标准路径下搜索. 所以,特别要注意的是,如果是标准库头文件,那么既可以采用<>的方式,又可以采用" "的方式,而用户自定义的头文件

关于C语言include尖括号和双引号的对话

A: #include "..." 和 #include <...> 有什么区别? B: 他喵的, 这么简单的问题. 尖括号是先在系统目录下找, 双引号是首先在当前目录下找, 找不到就找系统目录. A: 说得很含糊. 那么我问你, 当前目录有个叫hdr.h的文件,     当前目录下还有一个子目录sub, sub里面有两个文件hdr.h和1.c,    1.c中#include "hdr.h",    那么在当前目录编译sub/1.c, 它应该包含哪一个

C语言中 单引号与双引号的区别

在C语言中,字符用单引号,字符串用双引号.在c1='a';中,'a'是字符常量,必须用单引号."a"表示字符串,包含两个字符,一个是'a',一个是'\0'. 用数组来存储字符串. int main() { char ch[2] = "A"; } 简言之,单引号是一个字符,,双引号是字符串, 原文地址:https://www.cnblogs.com/654321cc/p/9266101.html

[C++]关于头文件中的防卫式声明(#ifndef...#pragma once)

大家知道,我们写.h文件时,通常会加上防卫式声明,有以下两种方式: 1. 宏定义 #ifndef _FILENAME_ #define _FILENAME_ //... #endif 2. 编译器指令 #pragma once 但是,为什么头文件中需要添加这种防卫式声明呢?如果没有这样的声明,会出现怎样的问题.这里,先看一个例子. -- "Car.h",代码如下(并没有添加防卫式声明): // Car.h class Car { // ... }; -- "Person.h&

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

C++中#include包含头文件带 .h 和不带 .h 的区别? 如 #include <iostream> 和 #include <iostream.h> 包含的东西有哪些不同? 之前在写C++程序的时候只知道使用 #include <iostream> 的时候,使用函数前要用 using namespace std; 导入命名空间,而 #include <iostream.h> 则不用,这个得看C+ +标准化过程为C++开发者做了哪些有意义的工作. (

第2条:在类的头文件中尽量少引入其他头文件

@class (向前声明) #import 注意:如果在各自头文件中引入对方的头文件,则会导致“循环引用 ”. 虽然#import(而非#inculde指令)不会导致死循环,但却意味着两个类里有一个无法被正确编译.

OC高效率52:(二)类的头文件中尽量少引用其他头文件

// //  EOCPerson.h //  OC高效率52:类的头文件中尽量少引用其他头文件 // //  Created by Zoujie on 15/10/8. //  Copyright ? 2015年 Zoujie. All rights reserved. // #import <Foundation/Foundation.h> //#import "EOCEmployer.h" @class EOCEmployer;//向前申明该类,将引入头文件的时机尽量延