Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C++ Standard Library
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Standard headers== The following files contain the declarations of the C++ Standard Library. Legend:<br> {{color box|#E6E6B7}}: Deprecated<br> {{color box|#F99}}: Removed ===General=== Components that C++ programs may use for increased features. {| class="wikitable" ! Name !! Description |- | {{code|<any>}} || Added in [[C++17]]. Provides a type-erased class <code>std::any</code>. |- | {{code|<atomic>}} || Added in [[C++11]]. Provides class template <code>std::atomic</code>, its several template specializations, and more atomic operations. |- | {{code|<chrono>}} || Provides time elements, such as <code>std::chrono::duration</code>, <code>std::chrono::time_point</code>, and clocks. Since [[C++20]], a hefty amount of temporal features were added: calendars, time zones, more clocks, and string chrono formatting. |- | {{code|<concepts>}} || Added in [[C++20]]. Provides fundamental library [[Concepts (C++)|concepts]]. |- | {{code|<expected>}} || Added in [[C++23]]. Provides class template <code>std::expected</code>, a [[result type]]. |- | {{code|<functional>}} || Provides several [[function object]]s, designed for use with the standard algorithms. |- | {{code|<generator>}} || Added in [[C++23]]. Provides a [[Generator (computer programming)|coroutine generator]] that additionally supports nested yield operations on ranges. |- | {{code|<memory>}} || Provides facilities for [[memory management]] in C++, including the class template <code>std::unique_ptr</code>. |- | {{code|<memory_resource>}} || Added in [[C++17]]. Provides facilities for creating polymorphic memory allocators whose behaviors can change at runtime.<ref>{{Cite web|last=Filipek|first=Bartlomiej|title=Polymorphic Allocators, std::vector Growth and Hacking|url=https://www.bfilipek.com/2020/06/pmr-hacking.html|access-date=2021-04-30|language=en}}</ref> |- | {{code|<optional>}} || Added in [[C++17]]. Provides class template <code>std::optional</code>, an [[Option type|optional type]]. |- | {{code|<scoped_allocator>}} || Added in [[C++11]]. Provides <code>std::scoped_allocator_adaptor</code>. |- | {{code|<stacktrace>}} || Added in [[C++23]]. Provides [[stack trace]] operations. |- | {{code|<stdexcept>}} || Contains standard exception classes such as <code>std::logic_error</code> and <code>std::runtime_error</code>, both derived from <code>std::exception</code>. |- | {{code|<system_error>}} || Added in [[C++11]]. Defines <code>std::error_code</code> |- | {{code|<tuple>}} || Added in [[C++11]] and TR1. Provides a class template <code>std::tuple</code>, a [[tuple]]. |- | {{code|<type_traits>}} || Added in [[C++11]]. Provides metaprogramming facilities working with types. |- | {{code|<utility>}} || The [[Utility (C++)|utility file]] provides various utilities: class template <code>std::pair</code> (two-member [[tuple]]s), compile-time integer sequences, helpers in constructing vocabulary types, functions such as <code>std::move</code> and <code>std::forward</code>, and many more. The namespace <code>std::rel_ops</code> for automatically generating comparison operators is deprecated in [[C++20]] in favor of new defaulted comparison operators. |- | {{code|<variant>}} || Added in [[C++17]]. Provides a class template <code>std::variant</code>, a [[Tagged union|tagged union type]]. |} ===Language support=== Components that C++ programs may use for support during development. {| class="wikitable" ! Name !! Description |- | {{code|<compare>}} || Added in [[C++20]]. Provides [[Three-way comparison|three-way comparison operator]] support. |- | {{code|<coroutine>}} || Added in [[C++20]]. Provides [[coroutine]] support. |- | {{code|<debugging>}} || Added in [[C++26]]. Provides [[debugging]] support. |- | {{code|<exception>}} || Provides several types and functions related to [[exception handling]], including <code>std::exception</code>, the base class of all exceptions thrown by the Standard Library. |- | {{code|<initializer_list>}} || Added in [[C++11]]. Provides initializer list support. |- | {{code|<limits>}} || Provides the class template <code>std::numeric_limits</code>, used for describing properties of fundamental numeric types. |- | {{code|<new>}} || Provides operators <code>new</code> and <code>delete</code> and other functions and types composing the fundamentals of C++ [[memory management]]. |- | {{code|<source_location>}} || Added in [[C++20]]. Provides capturing source location information as alternative to predefined macros such as <code>__LINE__</code>. |- | {{code|<stdfloat>}} || Added in [[C++23]]. Provides conditional support for extended floating-point types. |- | {{code|<typeinfo>}} || Provides facilities for working with C++ [[run-time type information]]. |- | {{code|<version>}} || Added in [[C++20]]. Provides information about the implementation of the C++ standard library.<ref>{{Cite web|date=2020-04-01|title=Working Draft, Standard for Programming Language C++|url=http://open-std.org/JTC1/SC22/WG21/docs/papers/2020/n4861.pdf|url-status=live|access-date=2021-04-30|website=open-std.org|publisher=ISO/IEC|page=492|archive-url=https://web.archive.org/web/20200427145844/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4861.pdf |archive-date=27 April 2020 }}</ref> |} ===Containers=== {{See also|Standard Template Library}} Components that C++ programs may use for [[Container (abstract data type)|container data structures]]. {| class="wikitable" ! Name !! Description |- | {{code|<array>}} || Added in [[C++11]] and [[C++ Technical Report 1|TR1]]. Provides the container class template <code>[[array (C++)|std::array]]</code>, a container for a fixed sized array. |- | {{code|<bitset>}} || Provides the specialized container class <code>std::bitset</code>, a [[bit array]]. |- | {{code|<deque>}} || Provides the container class template <code>[[deque (C++)|std::deque]]</code>, a [[deque|double-ended queue]]. |- | {{code|<flat_map>}} || Added in [[C++23]]. Provides the container adapter class templates <code>std::flat_map</code> and <code>std::flat_multimap</code>. |- | {{code|<flat_set>}} || Added in [[C++23]]. Provides the container adapter class templates <code>std::flat_set</code> and <code>std::flat_multiset</code>. |- | {{code|<forward_list>}} || Added in [[C++11]] and [[C++ Technical Report 1|TR1]]. Provides the container class template <code>[[forward list (C++)|std::forward_list]]</code>, a [[Linked list|singly linked list]]. |- | {{code|<inplace_vector>}} || Added in [[C++26]]. Provides the class <code>std::inplace_vector</code>, analogous to <code>std::vector</code> with a fixed capacity defined at compile time. |- | {{code|<map>}} || Provides the container class templates <code>[[map (C++)|std::map]]</code> and <code>std::multimap</code>, sorted [[associative array]] and [[Multimap (data structure)|multimap]]. |- | {{code|<mdspan>}} || Added in [[C++23]]. Provides the class template <code>std::mdspan</code>, analogous to <code>std::span</code> but the view is multidimensional. |- | {{code|<queue>}} || Provides the container adapter class <code>std::queue</code>, a single-ended [[Queue (data structure)|queue]], and <code>std::priority_queue</code>, a [[priority queue]]. |- | {{code|<set>}} || Provides the container class templates <code>[[set (C++)|std::set]]</code> and <code>std::multiset</code>, sorted associative containers or [[Set (computer science)|set]]s. |- | {{code|<span>}} || Added in [[C++20]]. Provides the class template <code>std::span</code>, a non-owning view that refers to any contiguous range. |- | {{code|<stack>}} || Provides the container adapter class <code>[[stack (C++)|std::stack]]</code>, a [[Stack (data structure)|stack]]. |- | {{code|<unordered_map>}} || Added in [[C++11]] and [[C++ Technical Report 1|TR1]]. Provides the container class template <code>[[unordered map (C++)|std::unordered_map]]</code> and <code>std::unordered_multimap</code>, [[hash table]]s. |- | {{code|<unordered_set>}} || Added in [[C++11]] and [[C++ Technical Report 1|TR1]]. Provides the container class template <code>[[unordered set (C++)|std::unordered_set]]</code> and <code>std::unordered_multiset</code>. |- | {{code|<vector>}} || Provides the container class template <code>[[vector (C++)|std::vector]]</code>, a [[dynamic array]]. |} ===Iterators and ranges=== Components that C++ programs may use to manipulate iterators, ranges, and algorithms over ranges and containers. {| class="wikitable" ! Name !! Description |- | {{code|<algorithm>}} || Provides definitions of many [[algorithm]]s for use with containers and other ranges. |- | {{code|<execution>}} || Added in [[C++17]]. Provides execution policies for parallelized algorithms. |- | {{code|<iterator>}} || Provides classes and templates for working with [[iterator]]s. |- | {{code|<numeric>}} || Generalized numeric algorithms. |- | {{code|<ranges>}} || Added in [[C++20]]. Provides [[Range (computer programming)|ranges]] facilities and lazily evaluated adapters. |} ===Localisation=== Components that C++ programs may use for localisation and character encoding manipulation. {| class="wikitable" ! Name !! Description |- | style="background:#F99" | {{code|<codecvt>}} | style="background:#F99" | Provides code conversion facets for various character encodings. Deprecated since [[C++17]], removed in [[C++26]]. |- | {{code|<locale>}} || Defines classes and declares functions that encapsulate and manipulate the information peculiar to a [[Locale (computer software)|locale]]. |- | {{code|<text_encoding>}} || Added in [[C++26]]. Provides text encoding identifications. |} ===Strings=== Components that C++ programs may use for string manipulation. {| class="wikitable" ! Name !! Description |- | {{code|<charconv>}} || Added in [[C++17]]. Provides a locale-independent, non-allocating, and non-throwing string conversion utilities from/to integers and floating point. |- | {{code|<format>}} || Added in [[C++20]]. Provides a modern way of formatting strings including <code>std::format</code>. |- | {{code|<string>}} || Provides the C++ standard [[String (C++)|string]] classes and templates. |- | {{code|<string_view>}} || Added in [[C++17]]. Provides class template <code>std::basic_string_view</code>, an immutable non-owning view to any string. |- | {{code|<regex>}} || Added in [[C++11]]. Provides utilities for pattern matching strings using [[regular expressions]]. |} ===Streams, files, and input/output=== Components that C++ programs may use for input/output manipulation and file manipulation. {| class="wikitable" ! Name !! Description |- | {{code|<filesystem>}} || Added in [[C++17]]. Provides facilities for [[file system]] operations and their components. |- | {{code|<fstream>}} || Provides facilities for file-based input and output. See [[fstream]]. |- | {{code|<iomanip>}} || Provides facilities to manipulate output formatting, such as the [[Radix|base]] used when formatting integers and the [[arithmetic precision|precision]] of [[floating-point arithmetic|floating-point]] values. |- | {{code|<ios>}} || Provides several types and functions basic to the operation of iostreams. |- | {{code|<iosfwd>}} || Provides [[forward declaration]]s of several I/O-related class templates. |- | {{code|<iostream>}} || Provides C++ input and output fundamentals. See [[iostream]]. |- | {{code|<istream>}} || Provides <code>std::istream</code> and other supporting classes for input. |- | {{code|<ostream>}} || Provides <code>std::ostream</code> and other supporting classes for output. |- | {{code|<print>}} || Added in [[C++23]]. Provides formatted output utilities such as <code>std::print</code> supported for both C and C++ streams. |- | {{code|<spanstream>}} || Added in [[C++23]]. Provides <code>std::spanstream</code> and other fixed character buffer I/O streams. |- | {{code|<sstream>}} || Provides <code>std::stringstream</code> and other supporting classes for string manipulation. |- | {{code|<streambuf>}} || Provides reading and writing functionality to/from certain types of character sequences, such as external files or strings. |- | style="background:#F99" | {{code|<strstream>}} | style="background:#F99" | Provides input/output operations on array-backed streams. Deprecated in [[C++98]], removed in [[C++26]]. |- | {{code|<syncstream>}} || Added in [[C++20]]. Provides <code>std::osyncstream</code> and other supporting classes for synchronized output streams. |} ===Thread support library=== Components that C++ programs may use for threading and concurrent programming. {| class="wikitable" ! Name !! Description |- | {{code|<barrier>}} || Added in [[C++20]]. Provides <code>std::barrier</code>, a reusable thread barrier. |- | {{code|<future>}} || Added in [[C++11]]. In 32.9.1-1, this section describes 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. |- | {{code|<hazard_pointer>}} || Added in [[C++26]]. Provides [[Hazard pointer|<code>std::hazard_pointer</code>]]. |- | {{code|<latch>}} || Added in [[C++20]]. Provides <code>std::latch</code>, a single-use thread barrier. |- | {{code|<mutex>}} || Added in [[C++11]]. In 32.5-1, this section provides mechanisms for mutual exclusion: mutexes, locks, and call once. |- | {{code|<rcu>}} || Added in [[C++26]]. Provides [[Read-copy-update|read-copy-update mechanisms]]. |- | {{code|<shared_mutex>}} || Added in [[C++14]]. Provides facility for shared mutual exclusion. |- | {{code|<semaphore>}} || Added in [[C++20]]. Provides [[Semaphore (programming)|semaphore]] that models non-negative resource count. |- | {{code|<stop_token>}} || Added in [[C++20]]. In 32.3.1-1, this section describes components that can be used to asynchronously request that an operation stops execution in a timely manner, typically because the result is no longer required. Such a request is called a stop request. |- | {{code|<thread>}} || Added in [[C++11]]. Provide class and namespace for working with threads. |} ===Numerics library=== Components that C++ programs may use to perform seminumerical or mathematical operations. {| class="wikitable" ! Name !! Description |- | {{code|<bit>}} || Added in [[C++20]]. Provides bit manipulation facilities. |- | {{code|<complex>}} || Defines a class template <code>std::complex</code>, and numerous functions for representing and manipulating complex numbers. |- | {{code|<linalg>}} || Added in [[C++26]]. Provides [[linear algebra]] facilities. |- | {{code|<numbers>}} || Added in [[C++20]]. Provides mathematical constants defined in namespace <code>std::numbers</code>. |- | {{code|<simd>}} || Added in [[C++26]]. Provides data-parallel types and operations on these types. |- | {{code|<random>}} || Added in [[C++11]]. Facility for generating (pseudo-)random numbers and distributions. |- | {{code|<ratio>}} || Added in [[C++11]]. Provides compile-time rational arithmetic based on class templates. |- | {{code|<valarray>}} || Defines five class templates (<code>std::valarray</code>, <code>std::slice_array</code>, <code>std::gslice_array</code>, <code>std::mask_array</code>, and <code>std::indirect_array</code>), two classes (<code>std::slice</code> and <code>std::gslice</code>), and a series of related function templates for representing and manipulating arrays of values. |} ===C standard library=== {{Main article|C standard library}} Each header from the C Standard Library is included in the C++ Standard Library under a different name, generated by removing the '{{mono|.h}}' file extension, and adding a '{{mono|c}}' at the start; for example, '<code>time.h</code>' becomes '<code>ctime</code>'. The only difference between these headers and the traditional C Standard Library headers is that where possible the functions should be placed into the <code>std::</code> namespace. In ISO C, functions in the standard library are allowed to be implemented by [[C preprocessor|macros]], which is not allowed by ISO C++. Usage of the C headers with the '{{mono|.h}}' file extension is legal in C++ and used for compatibility. {| class="wikitable" ! Name !! Description |- | {{code|<cassert>}} || Related to <code>[[assert.h|<assert.h>]]</code>. Declares the [[assertion (computing)|assert]] macro, used to assist with detecting logical errors and other types of bugs while [[debugging]] a program. |- | style="background:#F99" | {{code|<ccomplex>}} | style="background:#F99" | Related to <code>[[complex.h|<complex.h>]]</code>. Defines a [[C mathematical functions#complex.h|set of functions]] for manipulating [[complex number]]s. Deprecated in [[C++17]], removed in [[C++20]]. |- | {{code|<cctype>}} || Related to <code>[[ctype.h|<ctype.h>]]</code>. Defines [[C character classification|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). |- | {{code|<cerrno>}} || Related to <code>[[errno.h|<errno.h>]]</code>. For testing error codes reported by library functions. |- | {{code|<cfenv>}} || Related to <code>[[errno.h|<errno.h>]]</code>. Defines a [[C mathematical functions#fenv.h|set of functions]] for controlling [[floating-point]] environment. |- | {{code|<cfloat>}} || Related to <code>[[float.h|<float.h>]]</code>. Defines [[C data types#float.h|macro constants]] specifying the implementation-specific properties of the [[floating-point]] library. |- | {{code|<cinttypes>}} || Related to <code>[[inttypes.h|<inttypes.h>]]</code>. Defines [[C data types#inttypes.h|exact-width integer types]]. |- | style="background:#F99" | {{code|<ciso646>}} | style="background:#F99" | Related to <code>[[iso646.h|<iso646.h>]]</code>. Defines [[C alternative tokens|several macros]] that implement alternative ways to express several standard tokens. For programming in [[ISO 646]] variant character sets. Removed in [[C++20]]. |- | {{code|<climits>}} || Related to <code>[[limits.h|<limits.h>]]</code>. Defines [[C data types#limits.h|macro constants]] specifying the implementation-specific properties of the integer types. |- | {{code|<clocale>}} || Related to <code><locale.h></code>. Defines [[C localization functions|localization functions]]. |- | {{code|<cmath>}} || Related to <code>[[math.h|<math.h>]]</code>. Defines [[C mathematical functions|common mathematical functions]]. Extends <code><math.h></code>, containing special mathematical functions such as [[Bessel function]]s and the [[Riemann zeta function]]. |- | {{code|<csetjmp>}} || Related to <code>[[setjmp.h|<setjmp.h>]]</code>. Declares the macros <code>setjmp</code> and <code>longjmp</code>, which are used for non-local exits. |- | {{code|<csignal>}} || Related to <code>[[signal.h|<signal.h>]]</code>. Defines [[C signal handling|signal-handling functions]]. |- | style="background:#F99" | {{code|<cstdalign>}} | style="background:#F99" | Related to <code><stdalign.h></code>. For querying and specifying the [[Data structure alignment|alignment]] of objects. Deprecated in [[C++17]], removed in [[C++20]]. |- | {{code|<cstdarg>}} || Related to <code>[[stdarg.h|<stdarg.h>]]</code>. For [[Linearizability|atomic operations]] on data shared between threads. |- | style="background:#F99" | {{code|<cstdbool>}} | style="background:#F99" | Related to <code>[[stdbool.h|<stdbool.h>]]</code>. Defines [[C data types#stdbool.h|a Boolean data type]]. Deprecated in [[C++17]], removed in [[C++20]]. |- | {{code|<cstddef>}} || Related to <code>[[stddef.h|<stddef.h>]]</code>. Defines [[C data types#stddef.h|several useful types and macros]]. |- | {{code|<cstdint>}} || Related to <code>[[stdint.h|<stdint.h>]]</code>. Defines [[C data types#stdint.h|exact-width integer types]]. |- | {{code|<cstdio>}} || Related to <code>[[stdio.h|<stdio.h>]]</code>. Defines [[C file input/output|core input and output functions]]. |- | {{code|<cstring>}} || Related to <code>[[string.h|<string.h>]]</code>. Defines [[C string handling|string-handling functions]]. |- | style="background:#F99" | {{code|<ctgmath>}} | style="background:#F99" | Related to <code>[[tgmath.h|<tgmath.h>]]</code>. Defines [[C mathematical functions#tgmath.h|type-generic mathematical functions]]. Deprecated in [[C++17]], removed in [[C++20]]. |- | {{code|<ctime>}} || Related to <code>[[time.h|<time.h>]]</code>. Defines [[C date and time functions|date- and time-handling functions]]. |- | {{code|<cuchar>}} || Related to <code><uchar.h></code>. Types and functions for manipulating [[Unicode]] characters. |- | {{code|<cwchar>}} || Related to <code>[[wchar.h|<wchar.h>]]</code>. Defines [[C string handling|wide-string-handling functions]]. |- | {{code|<cwctype>}} || Related to <code>[[wctype.h|<wctype.h>]]</code>. Defines [[C character classification|set of functions]] used to classify wide characters by their types or to convert between upper and lower case. |} 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. {| class="wikitable" ! Name !! Description |- | {{code|<stdatomic.h>}} || Added in [[C++23]]. Related to <code><stdatomic.h></code>. For [[Linearizability|atomic operations]] on data shared between threads. |} The C headers <code><stdnoreturn.h></code> and <code><threads.h></code> 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 "{{mono|c}}" at the beginning of the name, and all contain the {{mono|.h}} suffix in the header name. Most headers in the POSIX library typically have a C++ equivalent implementation, such as <code><regex></code> rather than <code><regex.h></code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)