c/c++中#include <>与#include""区别

本文介绍了C语言中两种不同的头文件包含方式:使用尖括号<>和双引号的区别。前者通常用于查找标准库提供的头文件,后者则先在当前目录下查找自定义的头文件。
<>先去系统目录中找头文件,如果没有在到当前目录下找。所以像标准的头文件 stdio.h、stdlib.h等用这个方法。


而""首先在当前目录下寻找,如果找不到,再到系统目录中寻找。 这个用于include自定义的头文件,让系统优先使用当前目录中定义的。


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 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.

[list]
[*]The #include method of file inclusion is often used to include [i]standard [/i]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.

[/list]

[list]
[*]The #include “file” method of file inclusion is often used to include [i]nonstandard [/i]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.

[/list]
当在C/C++使用Qt 5.15.2版本,加入`#include <QChartView>` `#include <QLineSeries>` `#include <QValueAxis>`后出现大量错误,可参考以下解决办法: 1. **在`.pro`文件中添加模块**:在项目的`.pro`文件里加上`QT += charts`,以确保Qt构建系统包含Qt Charts模块。示例如下: ```pro QT += core gui charts greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = YourProjectName TEMPLATE = app # 其他配置... ``` 2. **在头文件中添加必要的包含和命名空间**:在使用这些类的头文件(如`window.h`)中,添加必要的包含语句和命名空间声明。示例如下: ```cpp #include <QtCharts/QtCharts> QT_CHARTS_USE_NAMESPACE // 或者使用 using namespace QtCharts; ``` 同时,根据不同的构建模式(Debug或Release),添加相应的库引用: ```cpp #ifdef _DEBUG #pragma comment(lib,"Qt5Chartsd.lib") // Debug #else #pragma comment(lib,"Qt5Charts.lib") // Release #endif ``` 3. **检查项目属性配置**:确保项目属性中正确配置了Qt相关的包含目录、库目录和链接库。具体来说,需要检查以下几点: - **包含目录**:确保包含了Qt Charts模块的头文件目录。 - **库目录**:确保包含了Qt Charts库文件的目录。 - **链接器输入**:确保链接了`Qt5Charts.lib`(Release模式)或`Qt5Chartsd.lib`(Debug模式)。 4. **确保命名空间正确**:确保在代码中正确使用了Qt Charts的命名空间。可以使用`QT_CHARTS_USE_NAMESPACE`宏或者`using namespace QtCharts;`语句。示例如下: ```cpp #include <QtCharts/QChartView> #include <QtCharts/QLineSeries> #include <QtCharts/QValueAxis> QT_CHARTS_USE_NAMESPACE // 或者 #include <QtCharts> using namespace QtCharts; ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值