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.

This page is an overview hub, not just a raw converted reference leaf. Use it to choose the right library area first, then jump into the more detailed section or header pages.

# 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.

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

AreaWhat it coversStart hereTypical headers
Language supportCore 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 structuresOwning collections, views, iterators, and string abstractions for storing and traversing data.Containers, Iterators, Ranges<vector>, <map>, <span>, <ranges>
Algorithms and numericsGeneric algorithms, arithmetic helpers, random engines, math utilities, and time utilities.Algorithms, Numerics, Chrono<algorithm>, <numeric>, <random>, <chrono>
Text and I/OStreams, file system interaction, regular expressions, localization, and text formatting/encoding.I/O, Text, Locale, Regex<iostream>, <format>, <regex>, <text_encoding>
ConcurrencyShared-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

# Headers Added In Newer Standards

StandardNotable headersTheme
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.

ModelFormUse when
Header inclusion#include <vector>The default and still the most portable model across current build systems and compilers.
Header unit importimport <vector>;You are using C++20 modules support and your toolchain supports importable header units.
Library module importimport 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:

  • std exports the standard library declarations in namespace std.
  • std.compat exports 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.

If you are writing modern C++, prefer the C++ spellings such as <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

DRApplied toBehavior as publishedCorrect behavior
LWG 1C++98The language linkages of names from the C standard library were unspecified.They are implementation-defined.
LWG 119C++98The exception specifications of virtual functions could be strengthened.Only non-virtual functions may strengthen them.
LWG 147C++98The specification on non-member functions only considered global functions.It also considers non-global functions.
LWG 225C++98Standard library functions might call non-member functions from other namespaces due to argument-dependent lookup.That is prohibited unless otherwise specified.
LWG 336C++98<strstream> was not a C++ library header.It is a C++ library header.
LWG 343C++98Library header dependencies were not specified.They are specified in the synopses.
LWG 456C++98C++ 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 465C++98Identifiers 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 1178C++98C++ 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 2013C++11It was unspecified whether functions not required to be constexpr could still be declared constexpr by the implementation.That is prohibited.
LWG 2225C++98A diagnostic was required if a header was included at an incorrect position.No diagnostic is required.