gpt4 book ai didi

c++ - 为什么STL头文件没有扩展名?

转载 作者:可可西里 更新时间:2023-11-01 15:19:43 26 4
gpt4 key购买 nike

我有这个基本的疑问。STL header 没有 .h 扩展名。

#include <vector>
#include <map>

这背后有什么具体原因吗?任何人都知道这背后的历史,请分享。

编辑:

@GMan found Michael Burr's answer which addresses this question.

最佳答案

  • #include 指令不区分文件类型(它只是一种美化的复制粘贴操作)- 不会自动添加 .h。
  • 提供的 C++ 标准头文件没有 .h 扩展名
  • 有时供应商提供的向后兼容头文件具有相同的名称并添加了 .h 扩展名

这一切都与命名空间有关。 C++ 标准 header 的 .h 对应物通常 #includes 正确的 C++ 标准 header (没有 .h 扩展名),然后发出一堆使用(类似这样的东西):

文件:iostream.h

#include <iostream>

using std::iostream;
using std::ostream;
using std::ios;
...

而没有 .h 扩展名的头文件不会用所有已定义的类和类型污染命名空间。

关于c++ - 为什么STL头文件没有扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/901216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com