iostream
is a header file that provides declarations and prototypes that are an interface to part of the C++ standard library.
There's is, on your system, a file called "iostream" (no extension), the contents of which are copied and pasted (with recursive processing of #include
s) at the point where you write #include <iostream>
.
#include
directives always pull in the contents of header files, they never add "libraries". Header files often contain declarations and prototypes that are an interface to a library, but the actual libraries themselves are attached to your program by the linker, not the compiler. When linking a C++ program, the linker will automatically attach the C++ standard library unless you tell it not to, so you don't have to worry about that.
Similarly, the using namespace std
statement does not do the work of attaching the library. This statement only makes it so that you can write, for example, cout
or string
instead of qualifying them as std::cout
and std::string
. This works for any namespace, but is usually discouraged.
For the three examples you gave, they all give you the definitions and prototypes you need to use the iostream portion of the C++ standard library, but (2) is preferred, (1) is acceptable, and (3) is deprecated. (2) gives the additional convenience of being able to omit the std::
prefix (at the cost of reducing the variable names available for you to use yourself), and (3) includes a different file called "iostream.h" instead of "iostream", which is usually the same thing, but the file with the .h is a relic of pre-standard C++ and so may not be supported in future compilers.