为什么元组文档说要使用,例如:
#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?
发布评论
评论(6)
使用<>并不意味着“不要在当前目录中查找” - 它意味着在实现定义的位置查找,然后在其他地方查找,也是实现定义的。其中一个可以是当前目录,也可以都不是当前目录。这是 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.
的历史意义是查看系统标准位置。使用"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.据我所知,原因是区分属于应用程序的标头和来自外部库的标头。我不能说为什么他们没有使用这个约定。这只是一个惯例,而不是规则。
也许有人应该向 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?
使用<...>为了提升。这不是您的代码。除非你的代码是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.
来自 msdn:
From msdn:
您是在问两种包容风格之间的区别是什么,还是 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.