标题“tree.h”在任何地方都不是标准的。
C 标准
ISO/IEC 9899:1990(C89、C90)
C89 中的 15 个标准头文件是:
<assert.h> <limits.h> <signal.h> <stdlib.h>
<ctype.h> <locale.h> <stdarg.h> <string.h>
<errno.h> <math.h> <stddef.h> <time.h>
<float.h> <setjmp.h> <stdio.h>
ISO/IEC 9899:1990/Amd.1:1995
C94*(修正案 1)中引入的 3 个额外标头是:
<iso646.h> <wchar.h> <wctype.h>
ISO/IEC 9899:1999 (C99)
C99 中额外的 6 个标头是:
<complex.h> <inttypes.h> <stdint.h> <tgmath.h>
<fenv.h> <stdbool.h>
ISO/IEC 9899:2011 (C11)
C2011 中的 5 个额外标题(总共 29 个)是:
<stdalign.h> <stdatomic.h> <stdnoreturn.h> <threads.h> <uchar.h>
ISO/IEC 9045:2008(POSIX 2008,单一 Unix 规范)
请注意,POSIX 需要更多的标头(82 个,包括所有 C99 标头)。下面的列表重复了标准 C (C99) 标头。当然,Windows 需要一组不同的标题。
<aio.h> <libgen.h> <spawn.h> <sys/time.h>
<arpa/inet.h> <limits.h> <stdarg.h> <sys/times.h>
<assert.h> <locale.h> <stdbool.h> <sys/types.h>
<complex.h> <math.h> <stddef.h> <sys/uio.h>
<cpio.h> <monetary.h> <stdint.h> <sys/un.h>
<ctype.h> <mqueue.h> <stdio.h> <sys/utsname.h>
<dirent.h> <ndbm.h> <stdlib.h> <sys/wait.h>
<dlfcn.h> <net/if.h> <string.h> <syslog.h>
<errno.h> <netdb.h> <strings.h> <tar.h>
<fcntl.h> <netinet/in.h> <stropts.h> <termios.h>
<fenv.h> <netinet/tcp.h> <sys/ipc.h> <tgmath.h>
<float.h> <nl_types.h> <sys/mman.h> <time.h>
<fmtmsg.h> <poll.h> <sys/msg.h> <trace.h>
<fnmatch.h> <pthread.h> <sys/resource.h> <ulimit.h>
<ftw.h> <pwd.h> <sys/select.h> <unistd.h>
<glob.h> <regex.h> <sys/sem.h> <utime.h>
<grp.h> <sched.h> <sys/shm.h> <utmpx.h>
<iconv.h> <search.h> <sys/socket.h> <wchar.h>
<inttypes.h> <semaphore.h> <sys/stat.h> <wctype.h>
<iso646.h> <setjmp.h> <sys/statvfs.h> <wordexp.h>
<langinfo.h> <signal.h>
还要注意,X/Open Curses 需要另一组标头。 2009 年 11 月发布了该规范的新版本(第 7 版)(自 1996 年以来的第一次更新——主要区别在于失去了对 termcap 和准标准 C <varargs.h> 标头的官方支持)。
<curses.h> <term.h> <uncntrl.h>
Linux 标准库
您可能还需要使用其他标题。例如,在这些列表中没有提到 <getopt.h>,但如果您使用 GNU Getopt(例如,对于长选项),您将需要并使用该标头。根据LSB, Linux Standards Base,它是Linux 上的标准。旧版本的 LSB 在多个部分中被定义为 ISO/IEC 23360:2006;截至 2014 年 9 月 21 日,LSB 的当前版本为 4.1,但 5.0 版本处于测试阶段。文档的一部分定义了包含哪些标题,但在我查看的版本中没有方便的标题表。它与 POSIX 紧密结合,但具有超出 POSIX 定义的额外功能。
C++ 标准
ISO/IEC 14882:1998 (C++98)
标准列出了 32 个特定于 C++ 的标头:
<algorithm> <iomanip> <list> <ostream> <streambuf>
<bitset> <ios> <locale> <queue> <string>
<complex> <iosfwd> <map> <set> <typeinfo>
<deque> <iostream> <memory> <sstream> <utility>
<exception> <istream> <new> <stack> <valarray>
<fstream> <iterator> <numeric> <stdexcept> <vector>
<functional> <limits>
还有18个头对应来自C的头(对应C94):
<cassert> <ciso646> <csetjmp> <cstdio> <ctime>
<cctype> <climits> <csignal> <cstdlib> <cwchar>
<cerrno> <clocale> <cstdarg> <cstring> <cwctype>
<cfloat> <cmath> <cstddef>
有趣的是,附件 D (§D.7) 列出了一个已弃用的标头 <strstream>,该标头在标准的前面没有提及。在 GCC (g++) 7.2.0 中包含该标头会生成警告:
/opt/gcc/v7.2.0/include/c++/7.2.0/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or antiquated
header which may be removed without further notice at a future date.
Please use a non-deprecated interface with equivalent functionality
instead. For a listing of replacement headers and interfaces, consult
the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
标头<strstream> 明确列在标准的其他版本中。
ISO/IEC 14882:2011 (C++11)
C++11 中的 53 个 C++ 头文件是:
<algorithm> <initializer_list> <numeric> <system_error>
<array> <iomanip> <ostream> <thread>
<atomic> <ios> <queue> <tuple>
<bitset> <iosfwd> <random> <type_traits>
<chrono> <iostream> <ratio> <typeindex>
<codecvt> <istream> <regex> <typeinfo>
<complex> <iterator> <scoped_allocator> <unordered_map>
<condition_variable> <limits> <set> <unordered_set>
<deque> <list> <sstream> <utility>
<exception> <locale> <stack> <valarray>
<forward_list> <map> <stdexcept> <vector>
<fstream> <memory> <streambuf>
<functional> <mutex> <string>
<future> <new> <strstream>
与C(C11)相关的26个头文件是:
<cassert> <cinttypes> <csignal> <cstdio> <cwchar>
<ccomplex> <ciso646> <cstdalign> <cstdlib> <cwctype>
<cctype> <climits> <cstdarg> <cstring>
<cerrno> <clocale> <cstdbool> <ctgmath>
<cfenv> <cmath> <cstddef> <ctime>
<cfloat> <csetjmp> <cstdint> <cuchar>
ISO/IEC 14882:2014 (C++14)
基于草案标准 N3797 的标头临时列表位于 ISO/IEC JTC1/SC22/WG21 站点。数据来自第 17.6.1.2 节 Headers 中的表 14 和 15,修改如下。由于该标准尚未发布(截至 2014-09-21),此列表尚未确定。
C++14 中的 54 个 C++ 头文件是:
<algorithm> <initializer_list> <numeric> <strstream>
<array> <iomanip> <ostream> <system_error>
<atomic> <ios> <queue> <thread>
<bitset> <iosfwd> <random> <tuple>
<chrono> <iostream> <ratio> <type_traits>
<codecvt> <istream> <regex> <typeindex>
<complex> <iterator> <scoped_allocator> <typeinfo>
<condition_variable> <limits> <set> <unordered_map>
<deque> <list> <shared_mutex> <unordered_set>
<exception> <locale> <sstream> <utility>
<forward_list> <map> <stack> <valarray>
<fstream> <memory> <stdexcept> <vector>
<functional> <mutex> <streambuf>
<future> <new> <string>
C(C11)相关的26个头文件与C++11相比没有变化:
<cassert> <cinttypes> <csignal> <cstdio> <cwchar>
<ccomplex> <ciso646> <cstdalign> <cstdlib> <cwctype>
<cctype> <climits> <cstdarg> <cstring>
<cerrno> <clocale> <cstdbool> <ctgmath>
<cfenv> <cmath> <cstddef> <ctime>
<cfloat> <csetjmp> <cstdint> <cuchar>
与 C++11 相比,为 C++14 列出了一个新的标头,即<shared_mutex>。
注意:草案两次列出了一些标题(<deque>、<istream>、<stdexcept>、<unordered_set>)。此外,C++11 的 5 个标头未在草案的表格中列出,即<exception>、<iterator>、<ratio>、<scoped_allocator> 和<thread>。由于§18.8 定义<exception>,§24 定义<iterator>,§20.11 定义<ratio>,§30 定义<thread>,以及§30.4 定义<shared_mutex>,这就是为什么你不应该相信标准草案的例子作为最终决定——它们包含错误。
ISO/IEC 14882:2017 (C++17)
基于 2017 年 3 月 21 日草稿 N4659 的 C++17 标头临时列表。这是对第 20.5.1.2 节 Headers 中表 16 和 17 的转录。这不是最终标准;理论上,有些事情可能会改变。
有 61 个 C++ 头文件:
<algorithm> <future> <numeric> <strstream>
<any> <initializer_list> <optional> <system_error>
<array> <iomanip> <ostream> <thread>
<atomic> <ios> <queue> <tuple>
<bitset> <iosfwd> <random> <type_traits>
<chrono> <iostream> <ratio> <typeindex>
<codecvt> <istream> <regex> <typeinfo>
<complex> <iterator> <scoped_allocator> <unordered_map>
<condition_variable> <limits> <set> <unordered_set>
<deque> <list> <shared_mutex> <utility>
<exception> <locale> <sstream> <valarray>
<execution> <map> <stack> <variant>
<filesystem> <memory> <stdexcept> <vector>
<forward_list> <memory_resource> <streambuf>
<fstream> <mutex> <string>
<functional> <new> <string_view>
与 C++14 相比,新的标头似乎是:<any>、<execution>、<filesystem>、<memory_resource>、<optional>、<string_view>、<variant>。
同样,与C(C11)相关的26个头文件与C++11和C++14相比没有变化:
<cassert> <cinttypes> <csignal> <cstdio> <cwchar>
<ccomplex> <ciso646> <cstdalign> <cstdlib> <cwctype>
<cctype> <climits> <cstdarg> <cstring>
<cerrno> <clocale> <cstdbool> <ctgmath>
<cfenv> <cmath> <cstddef> <ctime>
<cfloat> <csetjmp> <cstdint> <cuchar>
另见What are the new features in C++17?
请注意,在 C++17 中,某些“C 库”标头是 deprecated,特别是 <ccomplex>、<cstdalign>、<cstdbool>、<ctgmath>(而不是 <ciso646>)。 C++ 标头 <codecvt>(在 C++11 中添加)在 C++17 中也已弃用。
*日期中的“推迟一年”问题是由于标准获得批准后处理该标准所需的时间。 ANSI 在1989 中批准了原始C 标准; ISO 于 1990 年批准。修正案 1 于 1994 年获得批准;它于 1995 年发布。