Update Information

This important update concerns the use of C++ strings and standard header files.

C++ Strings

Even though The programmer's guide to C++ was only recently published, some features of the emerging ANSI standard have already affected it. When the book was written most C++ compilers did not incorporate the new standard library, so some of its proposed features where not incorporated in the many examples of C++ code in the text and model solutions. However, the latest versions of many C++ compilers are now being shipped with the new standard libraries which have to be used with namespaces and a new header file naming convention. The implications for the examples and exercises in the book are not serious except for the use of <string>.

The <string> standard library is now in a namespace. The best way to manage this is discussed below. But a very crude solution is to always follow the string include with a using namespace statement, thus:

#include <string>
using namespace std;

In the C++ standard library the declarations and definitions (except for names which are defined as macros in C) are within namespace scope of the namespace std. Section 13.4 on page 194 of The programmer's guide to C++ explains how namespaces work. In this case, it means that all the names in the libraries have to be prefixed with std::, as in the following:

#include <string>
...
void main()
{
  std::string myname;
  ...
}

Alternatively, the scope prefix can be avoided by putting a using statement at the start of the function, like this:

#include <string>
...
void main()
{
  using namespace std;
  ...
  string myname;
  ...
}

It is bad practice to put a using statement in a header file or in the global scope of a source file. There is more about namespaces.

Apart from the above namespace problem, The programmer's guide to C++ uses standard C++ strings. The description of C++ strings in Appendix B is correct, but does not include some of the latest features.

New Library Names

The new naming convention is used for the string library header throughout the book, but it is not used for other standard libraries. The relationship between the names used in the book and new library names is as follows:

 

name used in book

new name

<iostream.h>

<iostream>

<fstream.h>

<fstream>

<string.h>

<cstring>

<iomanip.h>

<iomanip>

<math.h>

<cmath>

<limits.h>

<climits>

<ctype.h>

<cctype>

<string>

<string>

<stdlib.h>

<cstdlib>

All the examples and model solutions in The programmer's guide to C++ that use libraries should work if the library header names are changed and a using statement as described above is added.

Appendix E in The programmer's guide to C++ lists most of the functions found in the standard C library, but the header file names are now incorrect. Converting them is easy. If a header is called <name.h> in the old library, it becomes <cname> in the new standard libraries. The new C standard library is in the stl namespace like the STL.