![]() | ||
2 c plus plus libraries and the c standard library
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. The C++ Standard Library provides several generic containers, functions to utilize and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O), support for some language features, and functions for everyday tasks such as finding the square root of a number. The C++ Standard Library also incorporates 18 headers of the ISO C90 C standard library ending with ".h", but their use is deprecated. No other headers in the C++ Standard Library end in ".h". Features of the C++ Standard Library are declared within the std
namespace.
Contents
- 2 c plus plus libraries and the c standard library
- Standard headers
- Containers
- General
- Localization
- Strings
- Streams and InputOutput
- Language support
- Thread support library
- Numerics library
- C standard library
- References
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. Although the C++ Standard Library and the STL share many features, neither is a strict superset of the other.
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. 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 O(n) or linearithmic time O(n log n), but in some cases higher bounds are allowed, such as quasilinear time O(n log2 n) for stable sort (to allow in-place merge sort). Previously sorting was only required to take O(n log n) 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), not requiring worst-case linear as in introselect.
The C++ Standard Library underwent ISO standardization as part of the C++ ISO Standardization effort, and is undergoing further work regarding standardization of expanded functionality.
Standard headers
The following files contain the declarations of the C++ Standard Library.
Containers
std::array
, a container for a fixed sized array.std::bitset
, a bit array.std::deque
, a double-ended queue.std::forward_list
, a singly linked list.std::list
, a doubly linked list.std::map
and std::multimap
, sorted associative array and multimap.std::queue
, a single-ended queue, and std::priority_queue
, a priority queue.std::set
and std::multiset
, sorted associative containers or sets.std::stack
, a stack.std::unordered_map
and std::unordered_multimap
, hash tables.std::unordered_set
and std::unordered_multiset
.std::vector
, a dynamic array.General
std::chrono::duration
, std::chrono::time_point
, and clocks.std::unique_ptr
.std::logic_error
and std::runtime_error
, both derived from std::exception
.std::tuple
, a tuple.std::pair
, for working with object pairs (two-member tuples), and the namespace std::rel_ops
, for easier operator overloading.Localization
Strings
Streams and Input/Output
std::istream
and other supporting classes for input.std::ostream
and other supporting classes for output.std::stringstream
and other supporting classes for string manipulation.Language support
std::exception
, the base class of all exceptions thrown by the Standard Library.std::numeric_limits
, used for describing properties of fundamental numeric types.new
and delete
and other functions and types composing the fundamentals of C++ memory management.Thread support library
Numerics library
Components that C++ programs may use to perform seminumerical operations.
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 .h, and adding a 'c' 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++.