This page was last updated August, 2004


The Standard C++ Library: Header Files


The Standard C++ Library provides a huge wealth of built in functions and functionality that is available to you to include in your programs. All this functionality becomes available when you #include the appropriate header files.

Naming conventions for header files in C and C++
  1. Standard C Library
  2. Standard C++ Library

Categories of Header Files Diagnostics - Provides diagnostic and debugging functionality and exception (run time error) handling. (<cassert>, <cerrno>, <stdexcept>)
Input/Output - All the headers providing input and output functionality, both standard C I/O and C++ stream I/O. (<cstdio>, <cstdlib>, <cwchar>, <fstream>, <iomanip>, <ios>, <iosfwd>, <iostream>, <ostream>, <strstream>, <streambuf>)
Language Support - Provides functionality for support of the C language. Advanced stuff with a lot of OS functionality. (<cfloat>, <climits>, <csetjmp>, <csignal>, <cstdarg>, <cstddef>, <cstdlib>, <ctime>, <exception>, <limits>)
Localization - Provides support for different cultural settings, i.e. other language supports. Chinese, Japanese, Korean, Russian, and Arabic languages for example (<clocale>, <locale>)
Numerics - Provides support for working with complex mathematical and numeric-related equations. (<cmath>, <complex>, <cstdlib>, <numeric>, <valarray>)
Strings - Support for strings and characters (<cctype>, <cstdlib>, <cstring>, <cwchar>, <cwctype>, <string>)
General Utilities - Miscellaneous useful functions for things like time and date, memory management, etc. (<ctime>, <functional>, <memory>, <utility>
Algorithms (STL) - An assortment of algorithm implementations that are part of the Standard Template Library. (<algorithms>, <cstdlib>,)
Containers (STL) - Provides an assortment of containers for the Standard Template Library. Many of the containers are variations on the Abstract Data Types of this class. (<deque>, <list>, <map>, <queue>, <set>, <stack>, <vector>)
Iterators (STL) - Functions used to iterate through the elements of a container. (<iterator>)

STL = Standard Template Library

Accessing the C++ header files.
All of the Standard C++ Library is wrapped in the standard namespace std. To have access to it, therefore you must either add the .h file extension or include a using, statement:
#include     // Include Standard C++ Library header 
using std::cout;       // Provide access to cout in the Std. C++ Lib.

	or

using namespace std;  // Get access to all of std namespace


What’s Where
The remainder of this page is a reference to some of the more useful header files and what is in them.

<ctype.h>
Functions to test characters. Argument must be an integer whose value is an unsigned char (ASCII 0-128) or EOF (-1). Functions return true if the character argument meets the conditions. This header file ncludes, but is not limited to...
isalnum(c) alphanumeric character (letter or digit)
isalpha(c) letter
iscntrl(c) control character (ASCII 0-31)
isdigit(c) decimal digit
islower(c) lower case letter
ispunct(c) printing character except for space or letter or digit, i.e. is punctuation
isspace(c) space, formfeed, newline, CR, tab, vertical tab, i.e. white space.
isupper(c) upper case letter
isxdigit(c) hexadecimal digit

Also includes two handy functions:

int tolower(int c) converts c to lower case if a letter
int toupper(int c) converts c to upper case if a letter

If c does not fit the required criteria (upper and lower case respectively, then c is returned unchanged.

<string.h>
Provides many "string" handling functions. Arguments are character arrays, or occasionally integers designating a length and/or location. Functions include but are not limited to...
char *strcpy(s,ct) Copy string ct to string s, including the '\0'; return s
char *strncpy(s,ct,n) Copy at most n charadcters of ct to s; return s
char *strcat(s,ct) Concatenate string ct to end of string s; return s.
char *strncat(s,ct,n) Concatenate at most n characters of ct to end of s; return s
int strcmp(cs,ct) Compare string cs to string ct; return <0 if cs<ct, 0 if cs==ct, or >0 if cs>ct
int strncmp(s,ct,n) Compare at most n characters of string cs to string ct; return <0 if cs<ct, 0 if cs==ct, or >0 if cs>ct
char *strchr(cs,c) Return pointer to first occurance of c in cs or NULL if not present.
char *strrchr(cs,c) Return pointer to last occurance of c in cs or NULL if not present.
char *strstr(cs,ct) Return pointer to first occurance of string ct in cs, or NULL if not present
size_t strlen(cs) Returns length of cs (treat as integer return value)
char *strtok(s,ct) Returns a token split from s using delimiters in ct. In other words this is a parser. Example: If ct=" \t\n", each call to strtok will split off a token from string s delimited by a space, tab, or newline.

<math.h>
Provides a variety of math functions. Functions include but are not limited to...
sin(x) Returns sine of x
cos(x) Returns cosine of x
tan(x) Returns tangent of x
asin(x) Returns arcsine of x in range [-π/2,π/2], x contained in [-1,1]
acos(x) Returns arcosine of x in range [0,π], x contained in[-1,1]
atan(x) Returns arctangent of x in range [-π/2,π/2]
sinh(x) Returns hyperbolic sine of x
cosh(x) Returns hyperbolic cosine of x
tanh(x) Returns hyperbolic tangent of x
exp(x) Returns function, ex
log(x) Returns natural logarithm, ln(x), x>0
log10(x) Returns base 10 logarithm, log10(x), x>0
pow(x,y) Returns xy, a domain error occurs if x=0 and y<=0,or if x<0 and y is not an integer.
sqrt(x) Returns sqrt of x, x>=0
ceil(x) Returns smallest integer not less than x
floor(x) Returns largest integer not greater than x

<stdlib.h>
The standard library includes a variety of useful functions including but not limited to...
double atof(const char *s) Converts string to float
int atoi(const char *s) Converts string to int
long atol(const char *s) Converts string to long
int rand(void) Returns pseudo-random number in range 0 to RAND_MAX which is usually 32767
void srand(unsigned int seed) Seeds random number generator with seed.

These next 4 can be used to dynamically allocat variables, arrays, etc. in C. These have largely been replaced by the use of the new function in C++:

void *calloc(size_t nobj, size_t size) Returns pointer to space for an array of nobj objects of size size or NULL if not enough memory. Space is initialized to zeros.
void *malloc(size_t size) Returns pointer to space for an object of size size or NULL if not enough memory. Space is uninitialized.
void *realloc(void *p, size_t, size) Reallocates the size of memory allocated to object pointed to by p
void free(void *p) Free the memory occupied by the object pointed to by p

void exit(int status) Causes an immediate normal program termination returning to the caller (usually the operating system) an integer status which can signal the exit status, ie. what has occured.
void system(const char *s) Used on UNIX and PC systems. Causes string s to be passed to the operating system to be executed as if it was typed on a command line.
int abs(int n) Returns absolute value of its integer argument. (don't know why this one is here and not in math.h)