【问题标题】:Difference between a `vector` created from the std `<vector>` library, and an `STL vector` created from: `<stl_vector.h>`从 std `<vector>` 库创建的 `vector` 和从 `<stl_vector.h>` 创建的 `STL vector` 之间的区别
【发布时间】:2022-01-12 11:23:54
【问题描述】:

为什么STD库中有两个不同的向量库?


  1.  stl_vector.h
  2.  vector.h

两者有什么区别?

【问题讨论】:

  • 如果您环顾四周,您会发现 很多 特定于实现的头文件,而不是 std_vector.h。供参考:A list of the standard C++ headers.
  • stl_vector.hstl_vector_implementation_detail_do_not_include_directly.h 的简写。
  • 标头不是库。一旦您对标头机制的原始程度有了更透彻的了解,它将开始变得有意义。
  • @molbdnilo 你真的明白我在“理解方面”的位置。它帮助我重新思考了整个 C++ 系统是如何工作的。这些库是由许多文件构建的。这就是为什么有时我包含的库——通过#include 预处理器——会附加一个.h,这是我以前不理解的。简而言之。 STL 库是一个 HEADER 文件,但它是构成 &lt;vector&gt;的整个构建的一部分。无论如何,我想你会觉得你帮助我弄清楚了会很满意。

标签: c++ vector std header-files


【解决方案1】:

如果您查看into the file 本身,您会看到

/** @file bits/stl_vector.h
 *  This is an internal header file, included by other library headers.
 *  Do not attempt to use it directly. @headername{vector}
 */

您的代码不应直接包含stl_vector.h。它是 libstdc++ 的一个实现细节,在其他标准库实现中可能不存在。

【讨论】:

  • 你应该 #include &lt;vector&gt; 并且只有 &lt;vector&gt;
猜你喜欢
  • 2018-08-16
  • 1970-01-01
  • 1970-01-01
  • 2014-12-05
  • 1970-01-01
  • 2021-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-06-20
相关资源
最近更新 更多