#include

 首先温故一下

1. #include

属于预处理指令中的一种,其他的如#define #if...#else...#endif  #pragma #ifndef...#define...#endif(保护

宏);

 

用处:在系统编译之前,将包含文件中的内容拷贝到当前文件的当前位置之后,再进行编译。用来引入并使用别人开发的成果;

用法:可包含任何编译器能识别的C/C++代码文件,不只是是头文件,如.c,.hpp,.cpp,.hxx,.cxx等,甚至.txt,.abc等等都可以。

 

2. 区别#include"" V.S. #include<>

 

Quote from CSDN:

 

#include ""     
  This   form   instructs   the   preprocessor   to   look   for   include   files   in   the   same   directory   of   the   file   that   contains   the   #include   statement,   and   then   in   the   directories   of   any   files   that   include   (#include)   that   file.   The   preprocessor   then   searches   along   the   path   specified   by   the   /I   compiler   option,   then   along   paths   specified   by   the   INCLUDE   environment   variable.  

   预处理器会先搜寻当前工程的所在路径中查找包含文件,若没找到则在vs安装时环境变量指定的include 路径中寻找。
    
#include <>    
  This   form   instructs   the   preprocessor   to   search   for   include   files   first   along   the   path   specified   by   the   /I   compiler   option,   then,   when   compiling   from   the   command   line,   along   the   path   specified   by   the   INCLUDE   environment   variable.   
  预处理器在vs 默认的include路径中查找文件。

两者区别在于查找速度。

结论:如果#include 包含用户自定义的文件,则使用"";若使用开发工具自带的文件,则用<>较快。

 

3. #include <iostream> V.S. #include <iostream.h>

从技术上说,其实没有<iostream.h>这样的东西——标准化委员会在简化非C标准头文件时用<iostream>取代了它;

从功能性的角度来讲, <iostream>包含了一系列模板化的I/O类,相反地<iostream.h>只仅仅是支持字符流。

#include   <iostream.h>是为了保持对原来C的兼容,头文件内容在全局空间而非名字空间std;而#include   <iostream> 只是使用namespace std 中iostream库的元素,是C++ 的标准,即需联合使用:

#include   <iostream>

using namespace std;

 

P.S.: 对于VS2008,编译器不再同时支持<iostream.h> 和<iostream>,只可使用C++标准<iostream>.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值