ANSI C++
Standard header files
cplusplus.com

In ANSI-C++ the way to include header files from the standard library has changed.

The standard specifies the following modification from the C way of including standard header files:

Here you have a list of the standard C++ header files:

<algorithm>   <bitset>   <deque>   <exception>   <fstream>   <functional>   <iomanip>   <ios>   <iosfwd>   <iostream>   <istream>   <iterator>   <limits>   <list>   <locale>   <map>   <memory>   <new>   <numeric>   <ostream>   <queue>   <set>   <sstream>   <stack>   <stdexcept>   <streambuf>   <string>   <typeinfo>   <utility>   <valarray>   <vector>  
And here is a list of the C header files included in ANSI-C++ with their new name and their equivalents in ANSI-C:
ANSI-C++ ANSI-C
<cassert><assert.h>
<cctype><ctype.h>
<cerrno><errno.h>
<cfloat><float.h>
<ciso646><iso646.h>
<climits><limits.h>
<clocale><locale.h>
<cmath><math.h>
<csetjmp><setjmp.h>
<csignal><signal.h>
<cstdarg><stdarg.h>
<cstddef><stddef.h>
<cstdio><stdio.h>
<cstdlib><stdlib.h>
<cstring><string.h>
<ctime><time.h>
<cwchar><wchar.h>
<cwtype><wtype.h>

Since now classes and functions of the standard libraries are located within the std namespace we must use the C++ using directive for that these become usable in the same way they were in pre-standard code. For example, to be able to use all the standard classes of iostream we would have to include something similar to this:

#include <iostream>
using namespace std;
that would be equivalent to the old expression
#include <iostream.h>
previous to the standard.

Nevertheless for compatibility with ANSI-C, the use of name.h way to include C header files is allowed. Therefore, both following examples are valid and equivalent in a compiler which fulfills ANSI-C++ specifications:

// ANSI C++ example

#include <cstdio>
using namespace std;

int main ()
{
  printf ("Hello World!");
  return 0;
}
// pre ANSI C++ example
// also valid under ANSI C++, but deprecated

#include <stdio.h>

int main ()
{
  printf ("Hello World!");
  return 0;
}

In all the examples of the current version of The C++ tutorial it has been chosen to include the old way because to date is the most compatible format (and also shorter), although if you have a compiler that supports ANSI-C++ standard I recommended you the use of the new format in your programs.

©The C++ Resources Network, 2000 - All rights reserved
Return back
Return to Documents section