C++ includes take one of two forms:
#include <> or
#include "". The only difference is that the former tells the compiler to look within the STL (Standard Template Library) for the source code, while the latter instructs the compiler to look in the local project folder first. If the compiler doesn't find the file in the local folder, it will search the STL.
Certain header files seem to see a lot of use in low-level programming courses, especially those that focus on creating console-based programs. These include, but are not limited to:
As you read on, I will try to explain the use of each class, and show ways to implement it in your code.
From the MSDN Standard C++ Library Reference:
[This class] declares objects that control reading from and writing to the standard streams. This is often the only header you need to include to perform input and output from a C++ program.
iostream contains the following functions:
The functions used most often are
cout. These are used for console input and output, respectively; in other words, to read in character input from a console window and display character output back out to the console window.
This class is used to manipulate the input and output sent and received by the console window.
iomanip contains the following functions: ``
The functions I used most often are
setw. These are used for formatting the output sent to the console window.
setfill is used to define an automatically-inserted character,
setprecision is used to set the number of trailing digits displayed, and
setw sets a minimum width to an output string.
Using these three functions together, it is quite easy to format your output to mimic, say, an ATM screen, with the output formatted correctly for currency, without need for excessive code.
The easiest way to define the
list class is to think of it as an automatic array. A
list object is a dynamically re-sized collection of other objects, such as integers, floats, characters, and pointers.
map class is very similar to the list class, with the exception being that a
map object's collection is automatically sorted.
This class is mostly used to implement legacy C code. It contains a long list of functions. The functions I have used most often are:
The first three,
atol, are used to convert a character string into, in order, a float, integer, or long integer value.
rand is used to generate a pseudo-random number.
srand is used to "seed", or initialize, the random number generator, which helps to increase the randomness of any subsequent calls to the
string class is easily the most welcomed class to be added the STL, as it saves programmers from having to manually build either their own string class for each program or from having to deal with the complexities of character arrays.
string class implements it's own overloaded operators, and gives us access to the function
getline, which is extremely useful for when you wish to read in a line of text (from the console window) that contains spaces, a condition that the character inputs have issues dealing with.
math class, according to cplusplus.com, "declares a set of functions to compute common mathematical operations and transformations."