#include?!!


Hello i am learning c++, im trying to understand some codes, it has lots of #includes ...., what does it mean? what does this #include... do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <limits>
#include <string>
#include <iostream>
#include <sstream>
#include <functional>
#include <algorithm>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector> 
Last edited on
edit.. not sure if you mean "What are Includes" on a more conceptual level.

My understanding is they define the behavior of the functions that are linked to them. Like if you tried to do something like this, you wouldn't have to make the push_back function yourself because it was already "Included" with <vector>

1
2
3
4
  do {
    std::cin >> myint;
    myvector.push_back (myint);
  } while (myint);


I don't know about all of those but some of them you only have to #include when you are using specifics functions of C++

Like <iostream> would be for using cin / cout

<vector> if you use vectors
<string> for strings
<sstream> for stringstream
<ctime> for measuring clock cycles

a lot of the other ones you can look up for specific functions that you use.

I think the best way to learn what the includes do is to not use them and if you get a compile error figure out which part of your code requires the include. Then you will know to use that include when you are using that particular function.

I try to use as few includes as possible normally.
Last edited on
Try looking at this:
http://www.cplusplus.com/reference/

The current site you're on is a great site to learn C++

Here is a site that lets you write and compile programs:
http://www.compileonline.com/

Also this site is a great site to check out. Pretty similar to my textbook:
http://www.learncpp.com/
closed account (18hRX9L8)
cpluspluscom wrote:
EX: #include <iostream>
Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case, the directive #include <iostream>, instructs the preprocessor to include a section of standard C++ code, known as header iostream, that allows to perform standard input and output operations, such as writing the output of this program (Hello World) to the screen.


http://www.cplusplus.com/doc/tutorial/program_structure/
Last edited on
Thanx everyone!
Topic archived. No new replies allowed.