#include<>和#include""的区别(转…

这篇博客详细解释了C语言中#include预处理指令的作用,包括#include<>和#include""的区别。前者通常用于引用编译器标准库中的头文件,后者常用于引用项目相对路径的自定义头文件。在编译过程中,#include指令会将指定的头文件内容插入到源代码中,确保函数的声明和定义可用。如果项目目录下没有指定的头文件,编译器会搜索默认的头文件路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


首先明白一点:函数的使用都要进行定义和声明的!
.h是头文件头文件是包含函数声明和定义的文件;你平时写C语言时,用到的printf()() 和scanf()都是系统定义好的,而这些函数的定义就包含在stdio.h这个文件中!
#include是编译预处理指令,就是在编译前将stdio.h这个文件里的函数都添加到你写的cpp文件中,然后参与编译,生成.obj文件
如果没有这个指令,你用到的printf()()和scanf()编辑器就会报错:
error C2065: 'printf()undeclared identifier
  
< >引用的是编译器的类库路径里面的头文件
" "引用的是你程序目录的相对路径中的头文件

假如你编译器定义的自带头文件引用在C:\Keil\c51\INC\下面
则#include引用的就是C:\Keil\c51\INC\stdio.h这个头文件
不管你的项目在什么目录里,C:\Keil\c51\INC\stdio.h这个路径就定下来了
一般是引用自带的一些头文件:stdio.h、conio.hstring.hstdlib.h等等之类的。。

假如你的项目目录是在D:\Projects\tmp\
则#include "my.h" 引用的就是D:\Projects\tmp\my.h这个头文件
一般是用来引用自己写的一些头文件
如果使用" ",它是会先在你项目的当前目录查找是否有对应头文件
如果没有,它还是会在对应的引用目录里面查找对应的头文件
意思就是,使用#include "stdio.h"如果你项目目录里面,没有stdio.h这个头文件,它还是会定位到C:\Keil\c51\INC\stdio.h这个头文件的
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;ui version=&quot;4.0&quot;&gt; &lt;class&gt;Login&lt;/class&gt; &lt;widget class=&quot;QWidget&quot; name=&quot;Login&quot;&gt; &lt;property name=&quot;windowModality&quot;&gt; &lt;enum&gt;Qt::ApplicationModal&lt;/enum&gt; &lt;/property&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;0&lt;/x&gt; &lt;y&gt;0&lt;/y&gt; &lt;width&gt;652&lt;/width&gt; &lt;height&gt;385&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;windowTitle&quot;&gt; &lt;string&gt;图书馆管理系统&lt;/string&gt; &lt;/property&gt; &lt;widget class=&quot;QLabel&quot; name=&quot;label&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;20&lt;/x&gt; &lt;y&gt;20&lt;/y&gt; &lt;width&gt;111&lt;/width&gt; &lt;height&gt;41&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:16pt;&quot;&gt;用户登录&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&lt;/string&gt; &lt;/property&gt; &lt;property name=&quot;textFormat&quot;&gt; &lt;enum&gt;Qt::AutoText&lt;/enum&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QLabel&quot; name=&quot;user&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;150&lt;/x&gt; &lt;y&gt;90&lt;/y&gt; &lt;width&gt;60&lt;/width&gt; &lt;height&gt;41&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;用户名&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&lt;/string&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QLabel&quot; name=&quot;password&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;160&lt;/x&gt; &lt;y&gt;150&lt;/y&gt; &lt;width&gt;60&lt;/width&gt; &lt;height&gt;26&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;密码&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&lt;/string&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QLabel&quot; name=&quot;identify&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;140&lt;/x&gt; &lt;y&gt;180&lt;/y&gt; &lt;width&gt;91&lt;/width&gt; &lt;height&gt;59&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;身份类型&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&lt;/string&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QLineEdit&quot; name=&quot;userline&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;290&lt;/x&gt; &lt;y&gt;100&lt;/y&gt; &lt;width&gt;191&lt;/width&gt; &lt;height&gt;21&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QLineEdit&quot; name=&quot;pwline&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;290&lt;/x&gt; &lt;y&gt;150&lt;/y&gt; &lt;width&gt;191&lt;/width&gt; &lt;height&gt;21&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;echoMode&quot;&gt; &lt;enum&gt;QLineEdit::Password&lt;/enum&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QComboBox&quot; name=&quot;idbox&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;320&lt;/x&gt; &lt;y&gt;200&lt;/y&gt; &lt;width&gt;121&lt;/width&gt; &lt;height&gt;22&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;item&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;读者&lt;/string&gt; &lt;/property&gt; &lt;/item&gt; &lt;item&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;图书管理员&lt;/string&gt; &lt;/property&gt; &lt;/item&gt; &lt;item&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;系统管理员&lt;/string&gt; &lt;/property&gt; &lt;/item&gt; &lt;/widget&gt; &lt;widget class=&quot;QPushButton&quot; name=&quot;loginbt&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;250&lt;/x&gt; &lt;y&gt;270&lt;/y&gt; &lt;width&gt;93&lt;/width&gt; &lt;height&gt;28&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;登录&lt;/string&gt; &lt;/property&gt; &lt;/widget&gt; &lt;widget class=&quot;QPushButton&quot; name=&quot;exitbt&quot;&gt; &lt;property name=&quot;geometry&quot;&gt; &lt;rect&gt; &lt;x&gt;420&lt;/x&gt; &lt;y&gt;270&lt;/y&gt; &lt;width&gt;93&lt;/width&gt; &lt;height&gt;28&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name=&quot;text&quot;&gt; &lt;string&gt;退出&lt;/string&gt; &lt;/property&gt; &lt;/widget&gt; &lt;/widget&gt; &lt;resources/&gt; &lt;connections/&gt; &lt;/ui&gt; 完整修改这段UI代码
05-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值