C++ Standard Library
Template:Short description Template:Use dmy dates Template:C++ Standard library Template:C++ sidebar In the C++ programming language, the C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself.[1]
Overview
The C++ Standard Library provides several generic containers, functions to use and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O), support for some language features, and functions for common tasks such as finding the square root of a number. The C++ Standard Library also incorporates most headers of the ISO C standard library ending with "Template:Mono", but their use was deprecated (reverted the deprecation since C++23[2]).[3] C++23 instead considers these headers as useful for interoperability with C, and recommends against their usage outside of programs that are intended to be both valid C and C++ programs. No other headers in the C++ Standard Library end in "Template:Mono". Features of the C++ Standard Library are declared within the std namespace.
The C++ Standard Library is based upon conventions introduced by the Standard Template Library (STL), and has been influenced by research in generic programming and developers of the STL such as Alexander Stepanov and Meng Lee.[4][5] Although the C++ Standard Library and the STL share many features, neither is a strict superset of the other.[6][7] The naming conventions of the standard library use snake_case[8], with the exception of std::ios_base::Init[9], std::text_encoding::id enumerators[10], and month/weekday constants[11][12] (i.e. std::chrono::January, std::chrono::Sunday). The design of the C++ standard library, much like the C standard library, is minimalistic, and contains only core features for programming, lacking most of the more specialised features offered by the Java standard library or C# standard library. For more features, some third-party libraries such as Boost libraries and POCO C++ Libraries, which offer additional features, may be used to supplement the standard library. An implementation for a C++ standard library header is described as "freestanding" if the execution of the program does not rely on an operating system.
A noteworthy feature of the C++ Standard Library is that it not only specifies the syntax and semantics of generic algorithms, but also places requirements on their performance.[13] These performance requirements often correspond to a well-known algorithm, which is expected but not required to be used. In most cases this requires linear time <math>O(n)</math> or linearithmic time <math>O(n \log(n))</math>, but in some cases higher bounds are allowed, such as quasilinear time <math>O(n \log^2 (n))</math> for stable sort (to allow in-place merge sort). Previously, sorting was only required to take <math>O(n \log(n))</math> on average, allowing the use of quicksort, which is fast in practice but has poor worst-case performance, but introsort was introduced to allow both fast average performance and optimal worst-case complexity, and as of C++11, sorting is guaranteed to be at worst linearithmic. In other cases requirements remain laxer, such as selection, which is only required to be linear on average (as in quickselect),[14]Template:Better source needed not requiring worst-case linear as in introselect.
The C++ Standard Library underwent ISO standardization as part of the C++ ISO Standardization effort in the 1990s. Since 2011, it has been expanded and updated every three years[15] with each revision of the C++ standard.
C++20 specifies the introduction of standard library header units,[16] and C++23 adds full module support for the standard library.[17]
Implementations
| Name | Organization | Homepage | Acronym | Licence | Latest release |
|---|---|---|---|---|---|
| GNU C++ Standard Library | GNU Project and Free Software Foundation | [1] | libstdc++ | GPLv3 with GCC Runtime Library Exception | New major release once per year |
| LLVM C++ Standard Library | LLVM Developer Group | [2] | libc++ | Apache License 2.0 with LLVM Exceptions | Every 2 weeks |
| NVIDIA C++ Standard Library | Nvidia | [3] | libcudacxx | Apache License 2.0 with LLVM Exceptions | Template:Start date and age |
| Microsoft C++ Standard Library | Microsoft | [4] | MSVC STL | Apache License 2.0 with LLVM Exceptions | Daily |
| HPX C++ Standard Library for Parallelism and Concurrency | STELLAR Group | [5] | HPX | Boost Software License 1.0 | Template:Start date and age |
| Electronic Arts Standard Template Library | Electronic Arts | [5] | EASTL | BSD 3-Clause License | Template:Start date and age |
| Dinkum C++ Library | Dinkumware | [6] Template:Webarchive | Unknown | Commercial | Unknown |
| Cray C++ Standard Library | Cray User Group | [7] | Unknown | Commercial | Unknown |
Discontinued
Apache C++ Standard Library
The Apache C++ Standard Library is another open-source implementation. It was originally developed commercially by Rogue Wave Software and later donated to the Apache Software Foundation.[18] However, after more than five years without a release, the board of the Apache Software Foundation decided to end this project and move it to Apache Attic.[19]
See also
The following libraries implement much of the C++ Standard Library:
| Name | Homepage | Description |
|---|---|---|
| Abseil | [8] | An open source collection of libraries used internally by Google |
| Folly | [9] | A variety of C++17 libraries that are used extensively by Facebook |
| Bareflank Support Library | [10] | A C++ library where everything can be executed at compile time |
Namespace organisation
The C++ standard library is placed inside the std namespace. std was historically a flat namespace (unlike other languages like Java and C#, which extensively divide their respective standard libraries along nomenclatural, hierarchical lines), but since C++11 it has been further divided into sub-namespaces within it:
std(the main namespace of the standard library)[20]std::chrono(contains facilities for the date and time library)[21]std::contracts(contains facilities for reporting information on contract violations)[22]std::execution(contains the execution control library for asynchronous execution, includingtask<T>)[23]std::execution::system_context_replaceability(allows for replacement of the default implement of the parallel scheduler)[24]
std::filesystem(contains facilities for working with file system manipulation, includingdirectory_entry,path, etc.)[25]std::linalg(contains facilities for linear algebra)[26]std::literals(inlined namespace containing various operators for creating literals of an object)[27]std::literals::chrono_literals(inlined namespace containing various operators for creating literals of duration objects)[28]std::literals::complex_literals(inlined namespace containing various operators for creating literals of imaginary numbers)[29]std::literals::string_literals(inlined namespace containing various operators for creating literals of string objects)[30]std::literals::string_view_literals(inlined namespace containing various operators for creating literals of string-view objects)[31]
std::meta(contains facilities for static (compile-time) reflection with theinfotype representing reflection metadata)std::numbers(contains all numeric constants, such aspi,e, etc.)[32]std::placeholders(contains all placeholder objects_1,_2, ..., up to an implementation-defined maximum_N)[33]std::pmr(contains symbols for polymorphic memory resources, for flexible runtime-configured allocation, as well as versions of the standard library types usingpolymorphic_allocatoras the allocator)[34]std::ranges(contains symbols for working over ranges, which extend the algorithm/iterator libraries)[35]std::ranges::views(contains symbols for range adapters for creating views, for lazy collection manipulation without copies; also aliased asstd::views)[36]
std::regex_constants(contains various regular expression customisation constants, such asECMAScript,awk,grep, etc.)[37]std::rel_ops(contains automatically generated comparison operators, deprecated since C++20)[38]std::this_thread(contains facilities for manipulating the current thread)[39]
There is also a std::experimental namespace, with further sub-namespaces in std::experimental::* for various pre-standardised/technical specification features which may be implemented by some compiler vendors.[40]
The posix namespace is reserved by the standard for ISO/IEC 9945 and POSIX-related symbols, but it currently remains unused. Identifiers beginning with two underscores, or with one underscore immediately followed by a capital letter, are reserved by the standard. Additionally, the std and posix namespaces are reserved, and adding declarations/definitions into any of those namespaces (or nested namespaces within) constitute undefined behavior, with a few exceptions (such as std::hash<> and std::formatter<>).[41]
Standard modules
Although modules were first introduced in C++20, standard library modules were only standardised as part of the language in C++23. Prior to that, standard library header units were specified for C++20, but most compiler vendors support backporting standard library modules to C++20.[42][43] These named modules were added to include all items declared in both global and std namespaces provided by the importable standard headers. Macros are not allowed to be exportable, so users have to manually include or import headers that emit macros for use, or can be alternatively exported as compile-time constants.
The C++ standard has reserved std and std.* as module names,[44] however most compilers allow a flag to override this.[45]
The standard library modules are:
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1">std</syntaxhighlight> | C++23Template:Efn | Exports all declarations in namespace std and global storage allocation and deallocation functions that are provided by the importable C++ library headers including C library facilities (although declared in standard namespace).
|
| <syntaxhighlight lang="text" class="" style="" inline="1">std.compat</syntaxhighlight> | C++23Template:Efn | Exports the same declarations as the named module std, and additionally exports functions in global namespace in C library facilities. It thus contains "compat" in the name, meaning compatibility with C.
|
std.compat is not a submodule of std, but is named so to indicate the association the module bears to the std module (as a "compatibility" version of it). Despite there being only one module for the entire standard library, it has been proposed that additional modules providing other subsets of the standard library be added.[46][47]
Standard headers
The following files contain the declarations of the C++ Standard Library.
Legend:
Template:Color box: Deprecated
Template:Color box: Removed
General
Components that C++ programs may use for increased features.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><any></syntaxhighlight> | C++17 | Provides a type-erased class any.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cerrno></syntaxhighlight> | C++98 | Related to <errno.h>. For testing error codes reported by library functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><chrono></syntaxhighlight> | C++11 | Provides time elements, such as duration, time_point, and clocks. Since C++20, additional temporal features were added, including calendars, time zones, more clocks, and time formatting.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><concepts></syntaxhighlight> | C++20 | Provides fundamental library concepts. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><contracts></syntaxhighlight> | C++26 | Provides design by contract features. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><csetjmp></syntaxhighlight> | C++98 | Related to <setjmp.h>. Declares the macros setjmp and longjmp, which are used for non-local exits.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><csignal></syntaxhighlight> | C++98 | Related to <signal.h>. Defines signal-handling functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstdalign></syntaxhighlight> | C++98 | Related to <stdalign.h>. For querying and specifying the alignment of objects. Deprecated in C++17, removed in C++20.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstdbool></syntaxhighlight> | C++98 | Related to <stdbool.h>. Defines a Boolean data type. Deprecated in C++17, removed in C++20.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstddef></syntaxhighlight> | C++98 | Related to <stddef.h>. Defines several useful types and macros.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstdint></syntaxhighlight> | C++98 | Related to <stdint.h>. Defines exact-width integer types.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><ctime></syntaxhighlight> | C++98 | Related to <time.h>. Defines date- and time-handling functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><debugging></syntaxhighlight> | C++26 | Provides fundamental library concepts. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><expected></syntaxhighlight> | C++23 | Provides class template expected, a result type.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><functional></syntaxhighlight> | C++98 | Provides several function objects, designed for use with the standard algorithms. (See Functional (C++).) |
| <syntaxhighlight lang="text" class="" style="" inline="1"><generator></syntaxhighlight> | C++23 | Provides a coroutine generator that additionally supports nested yield operations on ranges. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><memory></syntaxhighlight> | C++98 | Provides facilities for memory management in C++, including the class template unique_ptr. (See Allocator (C++).)
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><memory_resource></syntaxhighlight> | C++17 | Provides facilities for creating polymorphic memory allocators whose behaviors can change at runtime.[48] (See Allocator (C++).) |
| <syntaxhighlight lang="text" class="" style="" inline="1"><optional></syntaxhighlight> | C++17 | Provides class template optional, an optional type.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><scoped_allocator></syntaxhighlight> | C++11 | Provides scoped_allocator_adaptor. (See Allocator (C++).)
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><stacktrace></syntaxhighlight> | C++23 | Provides stack trace operations. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdexcept></syntaxhighlight> | C++98 | Contains standard exception classes such as logic_error and runtime_error.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><system_error></syntaxhighlight> | C++11 | Defines error_code and features relating to its usage.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><tuple></syntaxhighlight> | C++11 | Provides a class template tuple, a tuple.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><type_traits></syntaxhighlight> | C++11 | Provides metaprogramming facilities working with types. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><utility></syntaxhighlight> | C++98 | The utility file provides various utilities: class template pair (two-member tuples), compile-time integer sequences, helpers in constructing vocabulary types, functions such as move and forward, and many more. The namespace std::rel_ops for automatically generating comparison operators is deprecated in C++20 in favor of new defaulted comparison operators.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><variant></syntaxhighlight> | C++17 | Provides a class template variant, a tagged union type.
|
Language support
Components that C++ programs may use for support during development.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cassert></syntaxhighlight> | C++98 | Related to <assert.h>. Declares the assert macro, used to assist with detecting logical errors and other types of bugs while debugging a program.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cfenv></syntaxhighlight> | C++98 | Related to <errno.h>. Defines a set of functions for controlling floating-point environment.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cfloat></syntaxhighlight> | C++98 | Related to <float.h>. Defines macro constants specifying the implementation-specific properties of the floating-point library.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cinttypes></syntaxhighlight> | C++98 | Related to <inttypes.h>. Defines exact-width integer types.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><ciso646></syntaxhighlight> | C++98 | Related to <iso646.h>. Defines several macros that implement alternative ways to express several standard tokens. For programming in ISO 646 variant character sets. Removed in C++20.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><climits></syntaxhighlight> | C++98 | Related to <limits.h>. Defines macro constants specifying the implementation-specific properties of the integer types.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><compare></syntaxhighlight> | C++20 | Provides three-way comparison operator support. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><coroutine></syntaxhighlight> | C++20 | Provides coroutine support. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><debugging></syntaxhighlight> | C++26 | Provides debugging support, such as breakpoints and other mechanisms to aid debuggers. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><exception></syntaxhighlight> | C++98 | Provides several types and functions related to exception handling, including exception, the base class of all exceptions thrown by the Standard Library.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><initializer_list></syntaxhighlight> | C++11 | Provides initializer list constructor support through initializer_list.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><limits></syntaxhighlight> | C++98 | Provides the class template numeric_limits, used for describing properties of fundamental numeric types.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><meta></syntaxhighlight> | C++26 | Provides reflective programming capabilities as well as symbol metadata and annotations. (See Reflection (C++).) |
| <syntaxhighlight lang="text" class="" style="" inline="1"><new></syntaxhighlight> | C++98 | Provides operators new and delete and other functions and types for placement allocation.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><source_location></syntaxhighlight> | C++20 | Provides source location information. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdfloat></syntaxhighlight> | C++23 | Provides conditional support for extended floating-point types. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><typeinfo></syntaxhighlight> | C++98 | Provides facilities for working with C++ run-time type information. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><version></syntaxhighlight> | C++20 | Provides information through macros about the provider's implementation of language features and the standard library.[49] |
Containers/collections
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}} Template:See also Components that C++ programs may use for container data structures.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><array></syntaxhighlight> | C++11 | Provides the container class template array, a container for a fixed-size array.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><bitset></syntaxhighlight> | C++98 | Provides the specialized container class bitset, a fixed-size bit array.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><deque></syntaxhighlight> | C++98 | Provides the container class template deque, a double-ended queue.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><flat_map></syntaxhighlight> | C++23 | Provides the container adapter class templates flat_map and flat_multimap.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><flat_set></syntaxhighlight> | C++23 | Provides the container adapter class templates flat_set and flat_multiset.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><forward_list></syntaxhighlight> | C++11 | Provides the container class template forward_list, a singly linked list.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><inplace_vector></syntaxhighlight> | C++26 | Provides the class inplace_vector, analogous to vector with a fixed capacity defined at compile time.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><hive></syntaxhighlight> | C++26 | Provides the class hive, which reuses erased elements' memory, essentially an object pool.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><map></syntaxhighlight> | C++98 | Provides the container class templates map and multimap, sorted associative array and multimap (typically by a red-black tree).
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><mdspan></syntaxhighlight> | C++23 | Provides the class template mdspan, analogous to span but for multidimensional views.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><queue></syntaxhighlight> | C++98 | Provides the container adapter class queue, a single-ended queue, and priority_queue, a priority queue.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><set></syntaxhighlight> | C++98 | Provides the container class templates set and multiset, sorted associative containers or sets.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"></syntaxhighlight> | C++20 | Provides the class template span, a non-owning view that refers to any contiguous range.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><stack></syntaxhighlight> | C++98 | Provides the container adapter class stack, a stack.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><unordered_map></syntaxhighlight> | C++11 | Provides the container class template unordered_map and unordered_multimap, hash tables.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><unordered_set></syntaxhighlight> | C++11 | Provides the container class template unordered_set and unordered_multiset.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><vector></syntaxhighlight> | C++98 | Provides the container class template vector, a dynamic array.
|
Iterators and ranges
Components that C++ programs may use to manipulate iterators, ranges, and algorithms over ranges and containers.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><algorithm></syntaxhighlight> | C++98 | Provides definitions of many algorithms for use with containers and other ranges. (See Algorithm (C++).) |
| <syntaxhighlight lang="text" class="" style="" inline="1"><iterator></syntaxhighlight> | C++98 | Provides classes and templates for working with iterators. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><numeric></syntaxhighlight> | C++98 | Generalized numeric algorithms. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><ranges></syntaxhighlight> | C++20 | Provides ranges facilities and lazily evaluated adapters. |
Localisation
Components that C++ programs may use for localisation and character encoding manipulation.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><clocale></syntaxhighlight> | C++98 | Related to <locale.h>. Defines localization functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><codecvt></syntaxhighlight> | C++11 | Provides code conversion facets for various character encodings. Deprecated since C++17, removed in C++26. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><locale></syntaxhighlight> | C++98 | Defines classes and declares functions that encapsulate and manipulate the information peculiar to a locale. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><text_encoding></syntaxhighlight> | C++26 | Provides text encoding identifications with the IANA Character Sets registry. |
Strings
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}} Components that C++ programs may use for string manipulation.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cctype></syntaxhighlight> | C++98 | Related to <ctype.h>. Defines set of functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known).
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><charconv></syntaxhighlight> | C++17 | Provides a locale-independent, non-allocating, and non-throwing string conversion utilities from/to integers and floating point. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstring></syntaxhighlight> | C++98 | Related to <string.h>. Defines string-handling functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cuchar></syntaxhighlight> | C++98 | Related to <uchar.h>. Types and functions for manipulating Unicode characters.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cwchar></syntaxhighlight> | C++98 | Related to <wchar.h>. Defines wide-string-handling functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cwctype></syntaxhighlight> | C++98 | Related to <wctype.h>. Defines set of functions used to classify wide characters by their types or to convert between upper and lower case.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><format></syntaxhighlight> | C++20 | Provides string formatting utilities. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><string></syntaxhighlight> | C++98 | Provides the C++ standard string classes and templates.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><string_view></syntaxhighlight> | C++17 | Provides string_view classes, representing an immutable non-owning view to any string.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><regex></syntaxhighlight> | C++11 | Provides utilities for pattern matching strings using regular expressions. |
Streams, files, and input/output
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}} Components that C++ programs may use for input/output manipulation and file manipulation.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstdio></syntaxhighlight> | C++98 | Related to <stdio.h>. Defines core input and output functions.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><filesystem></syntaxhighlight> | C++17 | Provides facilities for file system operations and their components. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><fstream></syntaxhighlight> | C++98 | Provides facilities for file-based input and output. See fstream. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><iomanip></syntaxhighlight> | C++98 | Provides facilities to manipulate output formatting, such as the base used when formatting integers and the precision of floating-point values. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><ios></syntaxhighlight> | C++98 | Provides several types and functions basic to the operation of iostreams. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><iosfwd></syntaxhighlight> | C++98 | Provides forward declarations of several I/O-related class templates. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><iostream></syntaxhighlight> | C++98 | Provides C++ input and output fundamentals. See iostream. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><istream></syntaxhighlight> | C++98 | Provides istream and other supporting classes for input.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><ostream></syntaxhighlight> | C++98 | Provides ostream and other supporting classes for output.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><print></syntaxhighlight> | C++23 | Provides formatted output utilities such as print supported for both C and C++ streams.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><spanstream></syntaxhighlight> | C++23 | Provides spanstream and other fixed character buffer I/O streams.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><sstream></syntaxhighlight> | C++98 | Provides stringstream and other supporting classes for string manipulation.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><streambuf></syntaxhighlight> | C++98 | Provides reading and writing functionality to/from certain types of character sequences, such as external files or strings. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><strstream></syntaxhighlight> | C++98 | Provides input/output operations on array-backed streams. Deprecated in C++98, removed in C++26. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><syncstream></syntaxhighlight> | C++20 | Provides osyncstream and other supporting classes for synchronized output streams.
|
Thread support library
Components that C++ programs may use for threading and concurrent programming.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><atomic></syntaxhighlight> | C++11 | Provides class template atomic, its several template specializations, and more atomic operations.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><barrier></syntaxhighlight> | C++20 | Provides barrier, a reusable thread barrier.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cstdarg></syntaxhighlight> | C++98 | Related to <stdarg.h>. For atomic operations on data shared between threads.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><execution></syntaxhighlight> | C++17 | Provides execution policies for parallelized algorithms. Expanded in C++26 with an execution control framework for asynchronous operations and tasks. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><future></syntaxhighlight> | C++11 | Provides components that a C++ program can use to retrieve in one thread the result (value or exception) from a function that has run in the same thread or another thread, such as future.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><hazard_pointer></syntaxhighlight> | C++26 | Provides hazard pointers via hazard_pointer.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><latch></syntaxhighlight> | C++20 | Provides latch, a single-use thread barrier.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><mutex></syntaxhighlight> | C++11 | Provides mechanisms for mutual exclusion: mutexes, locks, and call_once.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><rcu></syntaxhighlight> | C++26 | Provides read-copy-update mechanisms for safe reclamation. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><shared_mutex></syntaxhighlight> | C++14 | Provides facility for shared mutual exclusion. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><semaphore></syntaxhighlight> | C++20 | Provides semaphore utilities for non-negative resource count. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stop_token></syntaxhighlight> | C++20 | Provides components that can be used to asynchronously request that an operation stops execution in a timely manner. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><thread></syntaxhighlight> | C++11 | Provide class thread for working with threads. Later expanded in C++20 with jthread, which automatically joins upon destruction. Also contains namespace std::this_thread for operations on the currently executing thread.
|
Numerics library
Components that C++ programs may use to perform seminumerical or mathematical operations.
| Name | Description | |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><bit></syntaxhighlight> | C++20 | Provides bit manipulation facilities. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><ccomplex></syntaxhighlight> | C++98 | Related to <complex.h>. Defines a set of functions for manipulating complex numbers. Deprecated in C++17, removed in C++20.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><cmath></syntaxhighlight> | C++98 | Related to <math.h>. Defines common mathematical functions. Extends <math.h>, containing special mathematical functions such as Bessel functions and the Riemann zeta function.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><complex></syntaxhighlight> | C++98 | Defines a class template complex, and numerous functions for representing and manipulating complex numbers.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><ctgmath></syntaxhighlight> | C++98 | Related to <tgmath.h>. Defines type-generic mathematical functions. Deprecated in C++17, removed in C++20.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><linalg></syntaxhighlight> | C++26 | Provides linear algebra facilities. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><numbers></syntaxhighlight> | C++20 | Provides mathematical constants defined in namespace std::numbers.
|
| <syntaxhighlight lang="text" class="" style="" inline="1"><simd></syntaxhighlight> | C++26 | Provides data-parallel types (Single instruction, multiple data or SIMD) and operations on these types. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><random></syntaxhighlight> | C++11 | Facility for generating (pseudo-)random numbers and distributions. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><ratio></syntaxhighlight> | C++11 | Provides compile-time rational arithmetic based on class templates. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><valarray></syntaxhighlight> | C++98 | Defines five class templates (valarray, slice_array, gslice_array, mask_array, and indirect_array), two classes (slice and gslice), and a series of related function templates for representing and manipulating arrays of values.
|
C standard library
Template:Main article
Each header from the C Standard Library is included in the C++ Standard Library under a different name, generated by removing the 'Template:Mono' file extension, and adding a 'Template:Mono' at the start; for example, 'time.h' becomes 'ctime'. The only difference between these headers and the traditional C Standard Library headers is that where possible the functions should be placed into the std:: namespace. In ISO C, functions in the standard library are allowed to be implemented by macros, which is not allowed by ISO C++.
Usage of the C headers with the 'Template:Mono' file extension was deprecated in C++98, but later undeprecated in C++23 for compatibility use; nonetheless, they remain discouraged for pure C++ code.
The following headers are special C compatibility headers which do not have a corresponding C++ naming convention, meaning that the C headers must be used if the header is necessary.
| Name | Since | Description |
|---|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdatomic.h></syntaxhighlight> | C++23 | For atomic operations on data shared between threads. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdbit.h></syntaxhighlight> | C++26 | For manipulating and processing bits and bit sequences. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdchkint.h></syntaxhighlight> | C++26 | For checked integers. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><stdcountof.h></syntaxhighlight> | C++26 | For determining the length of a C array. |
The C headers <stdnoreturn.h> and <threads.h> do not have C++ equivalents and their C headers are not supported in C++.
C++ does not provide the C POSIX library as part of any standard, however it is legal to use in a C++ program. If used in C++, the POSIX headers are not prepended with a "Template:Mono" at the beginning of the name, and all contain the Template:Mono suffix in the header name. Most headers in the POSIX library typically have a C++ equivalent implementation, such as <regex> rather than <regex.h>.
Networking TS library
The following headers are defined in the C++ networking TS, itself based on the boost::asio library from Boost, which is not standardised in C++ yet.[50] Despite this, it is provided by some vendors, such as GCC.[51] The symbols are placed in std::extensions::net.
| Name | Description |
|---|---|
| <syntaxhighlight lang="text" class="" style="" inline="1"><netfwd></syntaxhighlight> | Contains forward declarations of Networking TS components. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><executor></syntaxhighlight> | Provides asynchronous models for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><io_context></syntaxhighlight> | Provides basic I/O services for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><timer></syntaxhighlight> | Provides timer operations for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><buffer></syntaxhighlight> | Provides buffers and buffer-oriented streams for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><socket></syntaxhighlight> | Provides sockets and socket streams for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><internet></syntaxhighlight> | Provides internet protocols for networking. |
| <syntaxhighlight lang="text" class="" style="" inline="1"><net></syntaxhighlight> | Includes all Networking TS headers. |
See also
- C standard library
- C POSIX library
- Windows API
- Windows.h
- Standard library
- Boost (C++ libraries)
- POCO C++ Libraries
- C++ Technical Report 1
Notes
References
Further reading
External links
- C++ Standard Library reference
- Microsoft C++ Standard Library Reference
- Rogue Wave SourcePro C++ documentation
- Apache C++ Standard Library Wiki, retired 15 May 2014 (based on Rogue Wave C++ Standard Library 4.1.0)
- STLport C++ Standard Library documentation
- The GNU C++ Library online documentation
- LLVM/Clang C++ Standard Library documentation
Template:C++ programming language Template:Apache Software Foundation
- ↑ ISO/IEC 14882:2003(E) Programming Languages – C++ §17-27
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ ISO/IEC 14882:2003(E) Programming Languages – C++ §D.5
- ↑ Template:Cite book
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ "Generic Algorithms Template:Webarchive", David Musser
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ "C++ IS Schedule Template:Webarchive", Herb Sutter
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ C++ Standards Committee. (2022). P2465R3 - C++ Modules: Design and Evolution. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2465r3.pdf Template:Webarchive
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ C++ Standards Committee. (2018). P0581R1 - Modules for C++. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0581r1.pdf
- ↑ C++ Standards Committee. (2021). P2412R0 - Further refinements to the C++ Modules Design. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2412r0.pdf Template:Webarchive
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}