When using c++, you first have the
build-in stuff. This includes the syntax and build-in datatypes such as int and char.
Then we have
standard librarys. Those are the files you can find the inlcude folder. Inside those librarys you can find functions and classes to peform commen or complicated tasks. For example, inside the library "iostream" you can find the classes cin and cout, to get input from the user or print output on the screen. And inside the library "string" you can find the class string, with all its memberfunctions. To use those things, you first have to include the library where they belong to.
Final, we have
self-written headerfiles. You can write those yourself, for example when you need some functions in different programs. Even for a single program it can be usefull to seperate your code into headerfiles, so you can easily find functions and classes etc.
The only difference between headerfiles and standard librarys are that standard librarys are known and used by all programmers. They're mostly included with compilers/IDE's. To include a standard library, you use
#include <library>
. To include a self-written headerfile, you use
#include "headerfile"
. With '<>' you tell the compiler to look in the include folder, with ' "" ' you tell the compiler to look in the same folder as the compiled sourcecode. When including a headerfile/library, it's like the code is written in the sourcecod itself. For example, we got a headerfile:
1 2 3 4 5
|
// headerfile.h
void printSomeText()
{
cout<<"SomeText";
}
|
And a .cpp file:
1 2 3 4 5 6 7 8 9 10 11 12
|
// sourcecode.cpp
#include <iostream>
using namespace std;
#include "headerfile.h"
int main()
{
printSomeText();
return 0;
}
|
This would be equal to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// sourcecode.cpp
#include <iostream>
using namespace std;
void printSomeText()
{
cout<<"SomeText";
}
int main()
{
printSomeText();
return 0;
}
|