C++ Standard Library
Overview of the major library families, header entry points, and modern include/import models.
The C++ standard library provides the reusable building blocks of the language: containers, algorithms, numerics, strings, I/O, concurrency, utilities, and the language support facilities that make the rest of the library work.
# Library Families
Foundations and utilities
General-purpose support types, tuples, pairs, optionals, variants, formatting helpers, and language support utilities.
Containers and access
Sequence, associative, and adaptor containers together with iterators and range-based traversal models.
Algorithms and numerics
Search, sort, transform, reduce, random generation, mathematical constants, and numeric computation support.
Numerics · Chrono · Formatting
Text, I/O, and locale
Stream I/O, regular expressions, locale-aware processing, and newer text formatting and encoding facilities.
Memory and lifetime
Dynamic allocation, allocators, smart pointers, uninitialized memory algorithms, and object-lifetime helpers.
Concurrency and runtime
Threads, atomics, synchronization primitives, futures, stop tokens, and execution-oriented support.
# Quick Map
| Area | What it covers | Start here | Typical headers |
|---|---|---|---|
| Language support | Core facilities the language relies on, such as allocation, exceptions, RTTI, and utility building blocks. | Utility, Type support, Error handling | <new>, <type_traits>, <exception>, <compare> |
| Data structures | Owning collections, views, iterators, and string abstractions for storing and traversing data. | Containers, Iterators, Ranges | <vector>, <map>, <span>, <ranges> |
| Algorithms and numerics | Generic algorithms, arithmetic helpers, random engines, math utilities, and time utilities. | Algorithms, Numerics, Chrono | <algorithm>, <numeric>, <random>, <chrono> |
| Text and I/O | Streams, file system interaction, regular expressions, localization, and text formatting/encoding. | I/O, Text, Locale, Regex | <iostream>, <format>, <regex>, <text_encoding> |
| Concurrency | Shared-state communication, synchronization, atomic operations, and cooperative cancellation. | Thread support, Atomic operations | <thread>, <mutex>, <atomic>, <future> |
# Headers
Every standard library entity is declared in a header, but the library is easier to navigate if you first choose the correct family and only then the exact header. For a flat list of header pages, see all C++ standard library headers.
# Common Header Groups
| Group | Representative headers | Primary destinations |
|---|---|---|
| Containers and views | <vector>, <array>, <map>, <span>, <mdspan> | Containers, Ranges |
| Algorithms and numerics | <algorithm>, <numeric>, <random>, <numbers>, <linalg> | Algorithms, Numerics |
| Text and formatting | <string>, <string_view>, <format>, <regex>, <text_encoding> | Strings, Text processing, Regex |
| Memory and utilities | <memory>, <memory_resource>, <utility>, <optional>, <variant> | Memory, Utility |
| Concurrency | <thread>, <mutex>, <atomic>, <future>, <stop_token> | Thread support, Atomic operations |
# Headers Added In Newer Standards
| Standard | Notable headers | Theme |
|---|---|---|
| C++11 | <array>, <chrono>, <condition_variable>, <forward_list>, <future>, <mutex>, <random>, <regex>, <thread>, <tuple>, <type_traits>, <unordered_map> | Modern baseline: concurrency, type traits, unordered containers, chrono, regex. |
| C++14 | <shared_mutex> | Shared locking support. |
| C++17 | <any>, <charconv>, <execution>, <filesystem>, <memory_resource>, <optional>, <string_view>, <variant> | Vocabulary types, filesystem, text conversion, and parallel algorithms. |
| C++20 | <barrier>, <bit>, <compare>, <concepts>, <format>, <latch>, <ranges>, <semaphore>, <span>, <source_location>, <stop_token>, <syncstream> | Ranges, concepts, new synchronization primitives, formatting, and comparison support. |
| C++23 | <expected>, <flat_map>, <flat_set>, <generator>, <mdspan>, <print>, <spanstream>, <stacktrace> | Expected-based error transport, modern printing, mdspan, and more flat/generator abstractions. |
| C++26 | <debugging>, <hazard_pointer>, <inplace_vector>, <linalg>, <rcu>, <simd>, <text_encoding> | Low-level concurrency, fixed-capacity containers, linear algebra, SIMD, and text encoding. |
# Using The Library
# Including Headers
The traditional model is #include. You include the header that declares the names you want to use, and the declarations become available in the translation unit.
| Model | Form | Use when |
|---|---|---|
| Header inclusion | #include <vector> | The default and still the most portable model across current build systems and compilers. |
| Header unit import | import <vector>; | You are using C++20 modules support and your toolchain supports importable header units. |
| Library module import | import std; or import std.compat; | You want the standardized library module surface introduced for modern module-based code. |
A translation unit may include library headers in any order, and most headers may be included more than once with no additional effect. The notable exception is cassert/assert.h, whose behavior depends on the current definition of NDEBUG.
# Importing Headers
In C++20 and later, implementations may provide importable header units. Conceptually these are still the same library headers, but reached through import rather than #include.
# Importing Modules
In C++23 and later, the standard library defines two named modules:
stdexports the standard library declarations in namespacestd.std.compatexports the same declarations and also the global-namespace names corresponding to the C library compatibility surface.
For codebases moving to modules, this gives you a cleaner entry point than importing many individual header units one by one.
# C Library Compatibility
The C++ standard library includes C compatibility headers such as <cstdio>, <cstdlib>, and <cmath>. These provide the C library facilities through the C++ library model, typically in namespace std, while some names may also remain available in the global namespace for compatibility.
<cstdio> over the legacy C header names such as <stdio.h>, unless you are intentionally working in a mixed C/C++ compatibility context.# Defect Reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 1 | C++98 | The language linkages of names from the C standard library were unspecified. | They are implementation-defined. |
| LWG 119 | C++98 | The exception specifications of virtual functions could be strengthened. | Only non-virtual functions may strengthen them. |
| LWG 147 | C++98 | The specification on non-member functions only considered global functions. | It also considers non-global functions. |
| LWG 225 | C++98 | Standard library functions might call non-member functions from other namespaces due to argument-dependent lookup. | That is prohibited unless otherwise specified. |
| LWG 336 | C++98 | <strstream> was not a C++ library header. | It is a C++ library header. |
| LWG 343 | C++98 | Library header dependencies were not specified. | They are specified in the synopses. |
| LWG 456 | C++98 | C++ headers for C library facilities could only provide definitions in namespace std. | They may also define in the global namespace and then inject into std. |
| LWG 465 | C++98 | Identifiers that are keywords or operators in C++ could be defined as macros in standard library headers. | All C++ standard library headers are forbidden from defining them as macros. |
| LWG 1178 | C++98 | C++ headers had to include another C++ header containing any needed definition. | Headers must directly or indirectly provide the declarations and definitions from their synopsis. |
| LWG 2013 | C++11 | It was unspecified whether functions not required to be constexpr could still be declared constexpr by the implementation. | That is prohibited. |
| LWG 2225 | C++98 | A diagnostic was required if a header was included at an incorrect position. | No diagnostic is required. |