#include <iostream>

So I recently started C++ but in the beginning you must always include something my theory is that it is a library of things you can read from like the following codes are just a book and each book you can use to your will or maybe not I've wondered this for a while but all I saw was tutorials that said "You just have to have it, it it might not make sense but use it anyway" type of thing maybe I'm a pointless noob maybe your a more experienced programmer but <insert witty snap back here>

p.s. Thanks to all the experienced programmers out there who answer these
The header files contain the implementations or the logic of the functions. For example, if you wanted to use cout, you would need to #include <iostream>, a header file that contains the rules on how cout works. The header files you include are determined by what you need to do in your program. You will also need using namespace std; in your programs. To put it simply, this statement allows you to write shorter code... among other things.
hmm.... so theoretically I could write a program without a header
If you want a good tutorial try this: http://www.cplusplus.com/doc/tutorial/program_structure.html
From there:

#include <iostream>
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.



If you want to know what is inside iostream go here: http://www.cplusplus.com/reference/iostream/


EDIT: You can write programs without including headers but it would be hard to make something useful
Last edited on
Topic archived. No new replies allowed.