C++11 新增頭文件(24 個)
來源:cppreference.com C++11 專頁 Headers 章節 與 標準庫頭文件列表,逐項核對提取。
C++11 新增頭文件分三類:全新 C++ 頭文件(20 個) 、自 C99 採納的 C 頭文件(4 個) ,另有若干兼容性頭文件。
1. 全新 C++ 頭文件(20 個)
| 頭文件 | 類別 | 用途 |
|---|---|---|
<array> |
容器 | std::array 定長數組容器 |
<forward_list> |
容器 | std::forward_list 單向鏈表 |
<unordered_map> |
容器 | std::unordered_map / unordered_multimap(哈希表) |
<unordered_set> |
容器 | std::unordered_set / unordered_multiset(哈希表) |
<tuple> |
工具 | std::tuple 異構值組 |
<initializer_list> |
工具 | std::initializer_list(支撐 {} 初始化) |
<typeindex> |
工具 | std::type_index |
<ratio> |
工具 | 編譯期有理數運算 |
<chrono> |
時間 | C++ 時間工具庫 |
<regex> |
文本 | 正則表達式庫 |
<codecvt> |
文本 | Unicode 轉換設施 ⚠ C++17 廢棄、C++26 移除 |
<random> |
數值 | 隨機數引擎與分佈 |
<type_traits> |
元編程 | 編譯期類型信息工具 |
<scoped_allocator> |
內存 | 嵌套(有狀態)分配器 |
<system_error> |
錯誤 | std::error_code 等平台錯誤碼體系 |
<thread> |
併發 | std::thread 線程類及支持函數 |
<mutex> |
併發 | 互斥量(mutex、lock_guard、unique_lock) |
<condition_variable> |
併發 | 線程等待條件 |
<future> |
併發 | 異步計算原語(promise/future/async/packaged_task) |
<atomic> |
併發 | 原子操作庫 |
2. 自 C99 採納的 C 頭文件(4 個)
| 頭文件 | 用途 |
|---|---|
<cstdint> |
定寬整數類型(int32_t、uint64_t......)及其他類型極限 |
<cinttypes> |
整數格式化宏、intmax_t / uintmax_t 的數學與轉換 |
<cuchar> |
C 風格 Unicode 字符轉換函數 |
<cfenv> |
浮點環境訪問(浮點捨入模式等) |
3. 兼容性頭文件
C++11 同時引入了對應的 .h 形式(名稱放入全局命名空間,不做 C++ 包裝):
.h 形式 |
對應 |
|---|---|
<stdint.h>、<inttypes.h> |
對應 <cstdint>、<cinttypes> |
<uchar.h>、<fenv.h> |
對應 <cuchar>、<cfenv> |
<complex.h>、<tgmath.h> |
簡單包含 <complex> / <complex>+<cmath> |
<stdalign.h>、<stdbool.h> |
兼容宏定義 |
以及 4 個後續被淘汰的兼容頭(了解即可,新代碼不要用):
| 頭文件 | 狀態 |
|---|---|
<ccomplex> |
C++11 引入 → C++17 廢棄 → C++20 移除(直接用 <complex>) |
<ctgmath> |
C++11 引入 → C++17 廢棄 → C++20 移除(<cmath> 已含等價重載) |
<cstdalign> |
C++11 引入 → C++17 廢棄 → C++20 移除 |
<cstdbool> |
C++11 引入 → C++17 廢棄 → C++20 移除 |
速記口訣
容器 4 個 (array / forward_list / 兩個 unordered),
併發 5 個 (thread / mutex / condition_variable / future / atomic),
時間 2 個 (chrono / ratio),
元編程 2 個 (type_traits / typeindex),
工具 4 個 (tuple / initializer_list / scoped_allocator / system_error),
文本隨機 3 個 (regex / codecvt⚠ / random),
C99 採納 4 個(cstdint / cinttypes / cuchar / cfenv)。
相關:庫特性詳解見 02_標準庫特性.md。