The C++ standard library headers may include each other in unspecified ways, so programmers generally shouldn't depend on one header including another. In a few cases, however, a header is guaranteed to include another header, or make available certain functions that would otherwise require inclusion of another header. What are those cases?
You need to use #include. In C, everything is explicit; don't expect it to work by magic.
There are two types of header files: the files that the programmer writes and the files that comes with your compiler. You request to use a header file in your program by including it with the C preprocessing directive #include, like you have seen inclusion of stdio. h header file, which comes along with your compiler.
C Standard library functions or simply C Library functions are inbuilt functions in C programming. The prototype and data definitions of these functions are present in their respective header files. To use these functions we need to include the header file in our program.
This answer ignores C headers - both the <meow.h>
and <cmeow>
ones. Of the C++ library headers (all references are to N4659):
<initializer_list>
is guaranteed to be included by:
<utility>
(§23.2.1 [utility.syn])<string>
(§24.3.1 [string.syn])<array>
(§26.3.2 [array.syn])<deque>
(§26.3.3 [deque.syn])<forward_list>
(§26.3.4 [forward_list.syn])<list>
(§26.3.5 [list.syn])<vector>
(§26.3.6 [vector.syn])<map>
(§26.4.2 [associative.map.syn])<set>
(§26.4.3 [associative.set.syn])<unordered_map>
(§26.5.2 [unord.map.syn])<unordered_set>
(§26.5.3 [unord.set.syn])<queue>
(§26.6.2 [queue.syn])<stack>
(§26.6.3 [stack.syn])<algorithm>
(§28.2 [algorithms.syn])<random>
(§29.6.2 [rand.synopsis])<valarray>
(§29.7.1 [valarray.syn])<regex>
(§31.4 [re.syn])<iostream>
is guaranteed to include <ios>
, <streambuf>
, <istream>
, and <ostream>
(§30.4.1 [iostream.syn]).
<ios>
is guaranteed to include <iosfwd>
(§30.5.1 [ios.syn]).
<bitset>
is guaranteed to include <string>
and <iosfwd>
(§23.9.1 [bitset.syn]).
The free function templates std::begin
, std::end
, the C++14 c-
, r-
, and cr-
versions, and the C++17 free function templates std::size
, std::empty
and std::data
nominally reside in <iterator>
, but are also available if any of the following headers is included: <array>
, <deque>
, <forward_list>
, <list>
, <map>
, <regex>
, <set>
, <string>
, <unordered_map>
, <unordered_set>
, and <vector>
(§27.7 [iterator.range], §27.8 [iterator.container]).
When <string_view>
is included, the *begin
and *end
functions, and the two generic std::swap
overloads defined in [utility.swap] (swap(T&, T&)
and swap(T (&a)[N], T (&b)[N])
) are guaranteed to be available. size/empty/data
, however, are not. (§24.4.1 [string.view.synop]).
Here are the mandatory includes for C++20, taken from N4860.
compare is included in:
initializer_list is included in:
string is included in:
iosfwd is included in:
concepts is included in:
iterator is included in:
ios, streambuf, istream are included in:
ostream is included in:
cinttypes is included in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With