Home Catalog Evaluate Download

The Deitel and Deitel book:

"C++ How To Program"

One of the best selling C++ programming textbooks is C++ How To Program (currently in its 4th edition) by Deitel and Deitel. The home page for this book can be found at:


You can go to the Amazon on-line bookstore (www.amazon.com) to observe that customers review this book very favorably. You might also be able to locate this book in your local library (be aware that many libraries will purchase a book when someone requests one they don't already have).

Messrs. Deitel and Deitel make available from their web site the source code that is shown in this book. On the web page listed above you can find a hyperlink labeled "Source-Code Download" which will allow you to download to your computer a single .ZIP file named cppHTP4_examples.zip which holds all of the source code illustrated in the book. After clicking on this hyperlink choose "Save this file to disk" and then specify a destination folder such as "C:\Deitel" or "C:\Computer Science Lab\CppIde\Deitel".

Because this .ZIP file holds only the .CPP and .H files, you will need to prepare project folders for each program before you can compile this code using any commercial IDE such as Microsoft's Visual C++ or Metrowerks CodeWarrior. This is a minor nuisance so I have already prepared the project files (.MAK makefiles and .PRJ files) that allow you to compile, execute, and debug these programs from my CPPIDE integrated development environment. You will find these project files in the folder named "Deitel and Deitel" on my Computer Science Lab CD-ROM.

Note that because the Computer Science Lab CD-ROM is an "auto-run" CD, my normal installation program will automatically display a Setup window a few seconds after you insert the CD-ROM. You have presumably already used this Setup program to install CPPIDE so you don't need to click on "Install". Instead, click on "Explore CD". This causes a normal Windows Explorer window to open, showing you the contents of the CD-ROM. Browse (navigate) to the folder named "Deitel and Deitel". Inside that folder you will see the following contents:

Deitel.htm                 [this is the file you are now reading]

Copy all of this content to the same destination folder where you unpacked the contents of cppHTP4_examples.zip. Then double-click on DeitelConvert.exe which will initiate the installation program that installs CPPIDE project folders for each of the example programs.

NOTE: It is important that you unpack the cppHTP4_examples.zip file BEFORE you initiate the DeitelConvert.exe executable.

Once this process is complete you will be able to navigate into the destination folder you selected and observe the following folder:


If you proceed into the cpphtp4_examples folder you will observe the following folders:


If you proceed into the ch01 (chapter 1) folder you will find the following folders:


If you proceed into the Fig01_02 folder you will find the following files:


The .CPP file is the Deitel and Deitel source code that originated in cppHTP4_examples.zip while the .MAK and .PRJ files originated from DeitelConvert.exe.

To compile any of the Deitel & Deitel example programs using CPPIDE, you simply need to open the corresponding .PRJ file and then click on the "Compile" button found on CPPIDE's toolbar.

There are a total of 275 example programs in all the chapters of the Deitel and Deitel book.

Some of these programs generate errors when they are compiled. For the most part, this is by design. For example, the Fig03_22.cpp program shown in chapter 3 generates a compiler error because it fails to initialize a reference at the time the reference variable is defined. As another example, the Fig05_12.cpp program shown in chapter 5 generates a compiler error because it attempts to modify a const object. Demonstrating these error messages is the whole point of these example programs.

But there are a few programs that won't compile with CPPIDE because CPPIDE employs the Gnu C++ compiler while Deitel and Deitel developed these programs using Microsoft's Visual C++ compiler. The difference is that the Gnu C++ compiler adheres very closely to the official C++ language standard whereas Microsoft has always been willing to invent their own standards. The programs that will not compile with the Gnu C++ compiler are listed below:

Fortunately, it is not difficult to get these programs to compile.

To make the Fig08_14.cpp program compile you just need to change:

for ( int i = 0; i < array.size(); i++ ) {


int i;
for ( i = 0; i < array.size(); i++ ) {

One way to get the Fig14_15.cpp program to compile is to change:

enum Choices { PRINT = 1, UPDATE, NEW, DELETE, END };


enum Choices { ePRINT = 1, eUPDATE, eNEW, eDELETE, eEND };

and then make the corresponding substitutions (ePRINT for PRINT, etc.) elsewhere in the program. Apparently the Gnu C++ compiler cannot handle seeing the reserved keywords of the C++ language used for enum members.

The problem with the Ex19_02.cpp program is that it employs the __TIMESTAMP__ macro which is not a part of the C++ language but rather a special feature of Microsoft's Visual C++ compiler. To make the Ex19_02.cpp program compile you just need to change:

<< "__TIMESTAMP__ = " << __TIMESTAMP__ << endl;


#ifdef _WIN32
<< "__TIMESTAMP__ = " << __TIMESTAMP__ << endl

Most of the programs in chapter 21 that don't compile can be made to compile simply by adding the following statement:

#include <iterator>

The only chapter 21 program that still won't compile with this fix is Fig21_15.cpp. For this program you also need to add the following statement:

#include <stdexcept>

Some of the example programs (for example, Fig04_17.cpp and Fig08_09.cpp) generate quite a few lines of text. If you are employing CPPIDE under Windows NT/2000/XP then the console window will be equipped with scroll bars which you can employ to read all of the text that is output to the window. But if you are running CPPIDE under Windows 95/98/ME then the console window lacks scroll bars (blame Microsoft) and you will only be able to observe the last page of text since the previous lines have scrolled off the top. The solution here is to run these programs from the console window (Start/Programs/MS-DOS Prompt) rather than from CPPIDE and to then pipe their output to "more", as is shown below:

<program name> | more

"More" is a paginator supplied by Microsoft which will halt the program after every page of text and wait for you to hit a key on the keyboard indicating you are ready for the next page.

One of the example programs, Fig20_03.cpp in chapter 20, requires command line parameters. To initiate this program from the command line you need to type more than just the program's name since you also want to give the program some additional arguments. From the MS-DOS prompt you could type something like:

fig20_03 <in_filename> <out_filename>

When you initiate a console-mode program using the "Execute" button seen on CPPIDE's toolbar, you don't get an opportunity to provide these additional command line arguments. However CPPIDE does offer this ability. Before initiating a program that requires command line arguments, open the Options dialog (View/Options) and then enter the command line arguments in the EDIT control labeled "command line arguments". Note that these command line arguments will continue to be sent to whatever programs you initiate with CPPIDE until you remove them.

Deitel and Deitel have placed a copyright notice at the end of many of their source files. Unfortunately the final line of this text does not end with a carriage return (\n character). This causes the Gnu compiler to issue the warning:

warning: no newline at end of file

This warning can be ignored. If you want to eliminate it, go to the very end of the source file and add a carriage return.

Some of the example programs (specifically, Fig02_22.cpp, Ex03_49.cpp, Fig12_04.cpp, Fig12_10.cpp, and Fig14_04.cpp) continue to accept user input until the operator types the EOF (end-of-file) character. You produce this EOF character on a Windows computer by typing CTRL+Z (that is, hold down the Ctrl key and then simultaneously depress the letter z).

The Fig14_07.cpp and Fig14_08.cpp programs require a data file named "clients.dat". This file can be constructed by first running the Fig14_04.cpp program which creates a clients.dat file in the Fig14_04 project folder. You then need to copy (or move) this clients.dat file to the Fig14_07 and Fig14_08 project folders before initiating those programs.

The Fig14_14.cpp and Fig14_15.cpp programs require a data file named "credit.dat". This file can be constructed by first running the Fig14_13.cpp program which creates a credit.dat file in the Fig14_13 project folder. You then need to copy (or move) this credit.dat file to the Fig14_14 and Fig14_15 project folders before initiating those programs.

Book Errata

The cppHTP4_examples.zip file holds a folder named "Fig06_05_07" and this folder holds a file named "Fig06_05.cpp" but the first line of this .CPP file identifies its contents as "fig06_07.cpp".

All of the example programs in chapter 15 are mislabeled. For example, the first line of the "Fig15_01.cpp" file states that it is the "fig16_01.cpp" file.

Some of the source files in chapter 17 are mislabeled

Deitel and Deitel offer a web page listing additional errata (typos) at the following hyperlink:


Return to the Catalog of Programs