Updated March 31, 2023
Introduction to C++ Header Files
Header files are used in this programs which contains definition or implementation of the predefine functions and variables. The header files can be used in this programs by using the preprocessor directives that is #include. All header files of this may or may not end by .h extension, where as in C all header files must end by .h extension.
Syntax
The syntax to include header files:
#include<iostream>
Or
#include"iostream"
Types of Header Files in C++
Types of header files
- System header files – These are predefined header files presents in this compilers.
- User header files – these are user defined header file includes in this programs by #define directive.
Next we see the list of system defined header files category wise below –
- Input/output library
<iostream> – This defines standard stream objects.
<ios> – This defines several typedefs and class template of std::ios_base class, std::basic_ios.
<istream> – This defines several typedefs and class template of std::basic_istream.
<ostream> – This defines several typedefs and class template of std::basic_ostream, std::basic_iostream.
<fstream> – This defines several typedefs and class template of std::basic_ifstream, std::basic_fstream, std::basic_ofstream.
<sstream> – This defines several typedefs and class template of std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream.
<iosfwd> – This defines library for input/output forward declarations classes.
<syncstream> – This defines several typedefs and class template of std::basic_osyncstream, std::basic_syncbuf.
<strstream> – This defines std::istrstream, std::strstream, std::ostrstream.
<iomanip> – This defines formatting function of input and output.
<streambuf> – This defines class template of std::basic_streambuf.
<cstdio> – This defines C input/output functions Concepts.
<concepts> – This defines library for fundamental concepts Coroutines.
<coroutine> – This defines library for coroutine support.
- Strings library
<cctype> – This defines library for Functions to determine character type.
<cwctype> – This defines library for Functions to determine wide character type.
<string> – This defines library for class template of std::basic_string.
<cstring> – This defines library for string handling functions of narrow character.
<cuchar> – This defines library for C Unicode character conversion functions.
<string_view> – This defines library for class template of std::basic_string_view.
<format> – This defines library for std::format.
<charconv> – This defines library for class template of std::from_chars and std::to_chars
- Containers library
<array> – This defines library for container of std::array.
<list> – This defines library for container of std::list.
<vector> – This defines library for container of std::vector.
<set> – This defines library for association container of std::set and std::multiset.
<unordered_set> – This defines library for association container of std::unordered_set and std::unordered_multiset.
<deque> – This defines library for container of std::deque.
<forward_list> – This defines library for container of std::forward_list.
<map> – This defines library for association container of std::map and std::multimap.
<unordered_map> – This defines library for unordered association container of std::unordered_map and std::unordered_multimap.
<stack> – This defines library for container adaptor of std::stack.
<span> – This defines library for view of std::span.
<queue> – This defines library for container adaptor of std::queue and std::priority_queue.
- Numerics library
<numbers> – This defines library for Math constants.
<cmath> – This defines library for mathematics functions.
<numeric> – This defines library for Numeric operations.
<complex> – This defines library for Complex number.
<valarray> – This defines library for arrays representing and manipulating of values class.
<random> – This defines library for generators and distributions of random number.
<ratio> – This defines library for Compile time rational arithmetic
<cfenv> – This defines library for functions to access Floating-point environment.
<bit> – This defines library for function for Bit manipulation.
- Error handling
<exception> – This defines library for utilities of Exception handling.
<system_error> – This defines library for platform-dependent error code, std::error_code.
<cerrno> – This defines library for error number.
<stdexcept> – This defines library for exception objects.
<cassert> – This defines library for macro(Conditionally compiled) that compares its argument to zero.
- Utilities library
<utility> – This defines library for utility.
<csignal> – This defines library for signal management.
<cstdlib> – This defines library for general purpose utilities like dynamic memory allocation, program control, sort, random numbers and search.
<csetjmp> – This defines library for an execution context like Macro or function that saves or jumps location.
<typeinfo> – This defines library for runtime type information utilities.
<cstdarg> – This defines library for handling argument lists of variable length.
<typeindex> – This defines library for std::type_index.
<bitset> – This defines library for class template std::bitset.
<type_traits> – This defines library for Compile time type information.
<functional> – This defines library for Function invocations, function objects, Reference wrappers and Bind operations.
<ctime> – This defines library for C time/date utilities.
<chrono> – This defines library for C++ time utilities.
<initializer_list> – This defines library for class template of std::initializer_list.
<cstddef> – This defines library for standard typedefs and macros.
<tuple> – This defines library for class template of std::tuple.
<optional> – This defines library for class template of std::optional.
<any> – This defines library for class template of std::any.
<variant> – This defines library for class template of std::variant.
<source_location> – This defines library for to obtain location of source code.
<compare>- This defines library for comparison operator.
<version> – This defines library for information implementation-dependent library.
- Numeric limits
<limits> – This defines library for to query properties of arithmetic types.
<climits> – This defines library for limits of integral.
<cstdint> – This defines library for fixed-size and limits of other data types.
<cfloat> – This defines library for limits of float.
<cinttypes> – This defines library for conversions, formatting macros , intmax_t and uintmax_t math.
- Dynamic memory management
<memory> – This defines library for utilities of higher level memory management.
<new> – This defines library for utilities of Low-level memory management.
<memory_resource> – This defines library for resource of Polymorphic allocators and memory.
<scoped_allocator> – This defines library for class of Nested allocator.
- Iterators library
<iterator> – This defines library for iterators range.
- Ranges library
<ranges> – This defines library for utilities and adaptors of Range access, primitives, requirements.
- Algorithms library
<execution> – This defines library for algorithm execution policies for parallel versions.
<algorithm> – This defines library for Algorithms used on ranges.
- Localization library
<clocale> – This defines library for utilization of C localization.
<locale> – This defines library for utilities Localization.
<codecvt> – This defines library for facilities of Unicode conversion.
- Filesystem library
<filesystem> – This define classes and functions for std::path.
- Regular Expressions library
<regex> – This defines library for regular expression classes, algorithms and iterators.
- Atomic Operations library
<atomic> – This defines library for Atomic operations.
- Thread support library
<stop_token> – This define stop tokens of std::jthread.
<thread> – This defines library for classes and function of std::thread.
<mutex> – This define primitives for mutual exclusion.
<shared_mutex> – This define primitives for shared mutual exclusion.
<semaphore> – This define semaphores.
<future> – This define asynchronous computations primitives.
<latch> – This define latches.
<condition_variable> – This define conditions for thread waiting.
<barrier> – This define barriers.
How and Why use C++ Header Files?
Next we write the example to see how and to why use header files below –
Code:
#include"iostream"
#include<string>
using namespace std;
int main()
{
string name;
cout <<"Please enter your name : ";
getline(cin,name);
cout<<"Your name is = "<<name;
return 0;
}
Output:
Conclusion
Header files definition for predefine functions and variables. To use a predefine function the specific header file needs to be include.
Recommended Articles
This is a guide to C++ Header Files. Here we discuss Introduction to Header Files, Types with codes, How and to why use with code and output. You can also go through our other related articles to learn more –