Search code examples
c++includeheader-fileslibrariesiostream

Is iostream a header or a library


I have just started learning cpp and one thing that is really confusing me is #include <iostream> or #include<vector>. Some people say that we are including iostream library and some say that #include is used for including header files. But iostream and vector don't have .h extension so how can they be header files? Also, can we include a library by using #include ? This also makes me think about difference between iostream.h and iostream . Which one is header file? Which one is library? If we are only including header files then why don't we write #include<vector.h>?

What does the standard cpp library contain? Smaller libraries like containers library , utilities library?

I tried looking on cppreference but couldn't understand


Solution

  • iostream and others are header files.

    Usually headers have .h or .hpp extension, but it's merely a convention. The C++ standard library uses a different convention, which is to have no extension.


    What counts as a library is moot. A "library" can mean either:

    1. A single .a, .so, .lib, or .dll file (or something else, depending on your platform).
    2. A collection of predefined entities for a programmer to use.

    The individual standard headers are definitely not (1). The whole standard library is (2), and is usually split into several (1)s.

    Whether each individual standard header counts as (2) is moot, I wouldn't call them that.

    The C++ standard splits the standard library into several header groups, and calls each a "library" (2). Cppreference does the same.