c++ - 在 C++ 中包含头文件时尖括号 < > 和双引号 ""之间的区别?

标签 c++ c c++11

Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?

尖括号< >有什么区别和双引号 " "同时在 C++ 中包含头文件?

我的意思是应该包含哪些文件,例如:#include <QPushButton>以及要包含哪些文件,例如:#include "MyFile.h" ???

最佳答案

它依赖于编译器。也就是说,一般使用 "将当前工作目录中的 header 优先于系统 header 。 <>通常用于系统头文件。从到规范(第 6.10.2 节):

A preprocessing directive of the form

  # include <h-char-sequence> new-line

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.

A preprocessing directive of the form

  # include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

  # include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any) from the original directive.

所以在大多数编译器上,使用""首先检查您的本地目录,如果找不到匹配项,则继续检查系统路径。使用 <>以系统标题开始搜索。

关于c++ - 在 C++ 中包含头文件时尖括号 < > 和双引号 ""之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3162030/

相关文章:

c++ - 使用 const 变量时无效使用非静态数据成员

c - 如何让 valgrind 显示守护进程应用程序的内存状态?

c++ - 为什么私有(private)成员变量上不允许使用 decltype?

c++ - "EXIT_FAILURE"是什么类别?

c++ - 何时在 Boost Test 库中使用手动注册?

c++ - 通过文本文件往返的 float 校验和

c - snprintf 缓冲区大小的负/零值

c++ - 为什么最后是垃圾字符?

c++ - <mutex> 和 <condition_variable> 的异常处理

C++0x 错误 : variable 'std::packaged_task<int> pt1' has initializer but incomplete type