首先温故一下
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>.

5493

被折叠的 条评论
为什么被折叠?



