使用“”包含 boost 头文件或<>

发布于 2024-08-14 11:11:28 字数 375 浏览 10 评论 0 原文

为什么元组文档说要使用,例如:

#include "boost/tuple/tuple.hpp"

我不

#include <boost/tuple/tuple.hpp>

知道我的代码不可能有一个名为“boost/tuple/tuple.hpp”的文件, 但使用 include <>明确指出不要查看当前目录。

那么原因是什么呢?

Why does tuple documentation say to use, for example:

#include "boost/tuple/tuple.hpp"

and not

#include <boost/tuple/tuple.hpp>

I know that it's not probable my code will have a file called "boost/tuple/tuple.hpp",
but using include <> states explicitly not to look in the curent directory.

So what is the reason?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

昔日梦未散 2024-08-21 11:11:28

使用<>并不意味着“不要在当前目录中查找” - 它意味着在实现定义的位置查找,然后在其他地方查找,也是实现定义的。其中一个可以是当前目录,也可以都不是当前目录。这是 C++ 标准中最无用的部分之一。

Using <> does not mean "don't look in the current directory" - It means look in an implementation defined place and then look somewhere else, also implementation defined. Either, both or neither of these could be the current directory. This is one of the more useless bits of the C++ standard.

牵强ㄟ 2024-08-21 11:11:28

的历史意义是查看系统标准位置。使用 "somefile" 意味着在当前目录以及其他一些位置中查找。

The historical meaning of <somefile> is to look in the system-standard places. With "somefile" it means look in the current directory, plus some other places.

爱要勇敢去追 2024-08-21 11:11:28

据我所知,原因是区分属于应用程序的标头和来自外部库的标头。我不能说为什么他们没有使用这个约定。这只是一个惯例,而不是规则。

也许有人应该向 Boost 维护者提出这个问题?

Afaik the reason is to differentiate between headers that belong to an application and those which are from external libraries. I can't say why they have not used this convention. It is a only a convention and not a rule.

Perhaps someone should raise this issue with the Boost maintainers?

红尘作伴 2024-08-21 11:11:28

使用<...>为了提升。这不是您的代码。除非你的代码是boost。

使用“....”作为头文件,这是每个 C++ 程序中不可避免的。这是给读者的,而不是给编译器的。

Use <...> for boost. This is not Your code. Unless your code is boost.

Use "...." for your header files, which you inevitably have in every C++ program. This is for the reader, not for the compiler.

倾其所爱 2024-08-21 11:11:28

来自 msdn

引用形式

该形式指示预处理器
在同一目录中查找包含文件
包含文件的目录
#include 语句,然后在
任何文件的目录
包含 (#include) 该文件。这
预处理器然后沿着
/I编译器指定的路径
选项,然后沿着指定的路径
INCLUDE 环境变量。

尖括号形式

该形式指示预处理器
首先搜索包含文件
沿着 /I 指定的路径
编译器选项,那么,编译时
从命令行,沿着路径
由 INCLUDE 环境指定
变量。

From msdn:

Quoted form

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.

Angle-bracket form

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.

梦明 2024-08-21 11:11:28

您是在问两种包容风格之间的区别是什么,还是 Boost 的基本原理?由于其他人已经谈到了差异,我将添加我对后一个问题的看法:

总的来说,我不认为任何一个都更正确。这取决于您的项目的依赖关系的结构。例如,在我的项目中,我通常将 Boost 等的相关部分包含在项目的子目录中,因此倾向于使用 #include "" 形式。如果您想从更全局的位置获取 Boost 安装,您会更喜欢 #include <> 形式。

Are you asking what the difference between the two styles of inclusion is, or for Boost's rationale? Since others have spoken regarding the difference, I'll just add my take on the latter issue:

I don't believe either is more correct, in general. It depends on how your project is structured with respect to its dependencies. For example, in my projects I typically include the relevant bits of Boost, et cetera, in a subdirectory of the project and thus tend to prefer the #include "" form. If you want to pick up the Boost installation from a more global location, you'd prefer the #include <> form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文