<< Function Declarations | Table of Contents | Standard IO >>
C++ contains a large standard library which includes all of the standard C library in addition to many additional modules containing C++ specific classes and functions.
Include Directive
To use a module from the standard library, you use the #include compiler directive. Modules from the C library are specified with the letter c preceding their name
(:source lang=cpp:)
#include <cstdio>
#include <cmath>
while C++ specific modules are indicated by name alone
(:source lang=cpp:)
#include <fstream>
The include directive has two forms. The bracket form illustrated above instructs the compiler to search for modules in the system directories only. To include a custom module (or one not located in he system directories), the
module name is enclosed within double quotes
(:source lang=cpp:)
#include "mymodule.h"
#include "graphics/window.h"
Modules in C++ consists of two files: a header file and an implementation file.
When a module is included within a program, it is the header file (with a .h extension) that is actually included. Thus, all non standard C and C++ library modules will be specified using a .h file extension.
Namespaces
The latest version of the C++ language has defined the use of namespaces which allow for duplication of function and class names within difference namespaces. All of the standard C++ modules use the std namespace. To use a function, variable or class from the standard namespace, you must either preceed the identifier with std
(:source lang=cpp:)
#include <iostream>
int main()
{
int age;
std.cout << "How old are you? ";
std.cin >> age;
}
or explicity tell the compiler you are using the standard namespace with the using clause
(:source lang=cpp:)
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "How old are you? ";
cin >> age;
}
Standard Library Modules
The following is a list of the standard C library modules included in C++
| Header File
| Description
|
| cctype
| character handling functions.
|
| cerrno
| error codes reported by some C functions.
|
| cfloat
| characteristics of floating-point types.
|
| climits
| sizes of integer types.
|
| cmath
| C mathematical functions.
|
| csignal
| signal handling functions and values.
|
| cstdarg
| variable arguments handling.
|
| cstddef
| C standard definitions.
|
| cstdio
| C standard and file input/output routines.
|
| cstdlib
| C standard general utility functions.
|
| cstring
| C-style string functions.
|
| ctime
| time and date routines.
|
The following is a list of the standard C++ library modules
| Header File
| Description
|
| string
| C++ string class for creating string objects.
|
| algorithm
| special collection of functions used on ranges.
|
| bitset
| container for storing bits.
|
| deque
| double ended queue.
|
| list
| sequence container implemented as a doubly-linked list.
|
| map
| map or dictionary type ADT.
|
| multimap
| multi-keyed map.
|
| multiset
| multi-key set.
|
| priority_queue
| priority queue ADT.
|
| queue
| the general queue ADT.
|
| set
| strucutre used for storing unique elements.
|
| stack
| the general stack ADT.
|
| vector
| the general vector ADT.
|
<< Function Declarations | Table of Contents | Standard IO >>