Home Catalog Evaluate Download

Bruce Eckel's book:

"Thinking In C++"

Bruce Eckel is the author of Thinking In C++, Volume 1 (2nd Edition) and Thinking In C++, Volume 2, which are two books that you could use to continue your C++ education. You can go to the Amazon on-line bookstore (www.amazon.com) and search on his name to see these books (as well as a Java book he has written). The customer reviews make it clear that these books are well regarded.

Many programming book authors make electronic versions of their books available before the book is actually published, since the immediate reader feedback helps them improve the work in progress. But Mr. Eckel is one of the very few programming book authors who continue to allow free downloads of their books even after they are published. You can read all about Mr. Eckel and this unusual business philosophy (which apparently has only increased the sale of his books!) on his web site at:

http://mindview.net/Books

Mr. Eckel allows reputable web sites to host (mirror) his books and has allowed me to place his two C++ books on my Computer Science Lab CD-ROM. You will find these books in a folder named "Eckel Thinking In C++". These two books are distributed in separate .ZIP files which you can unpack to a location on your hard drive.

When you unpack the TICPP-2nd-ed-Vol-one.zip file that holds the Volume 1 book you will discover a collection of .HTML files, one for each chapter. To begin reading this Volume 1 book double-click on the "Frames.html" file. Be sure to notice that Mr. Eckel has provided an excellent index which is composed of a large number of hyperlinks that will take you to an exact location in his book.

When you unpack the TICPP-2nd-ed-Vol-two.zip file that holds the Volume 2 book you will discover that it unpacks into 2 child folders named "html" and "code". In the "html" folder you will find a single, mammoth .HTML file named TicV2.html, which is the entire Volume 2 book. The "code" folder holds all the example programs. However Mr. Eckel uses an organization for his source code that doesn't work well with CPPIDE (he puts all the programs from a single chapter into a common bucket). So I have re-arranged his source code examples into individual CPPIDE projects and therefore you can toss his "code" folder.

Mr. Eckel also makes freely available the source code that is shown in his books. And he has allowed me to include this source code on my Computer Science Lab CD-ROM. I have provided the makefiles (.MAK) and project (.PRJ) files that allow Mr. Eckel's programs to integrate with my CPPIDE integrated development environment. You will find all this content in the folder named "Eckel Thinking In C++" 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 "Eckel Thinking In C++". Inside that folder you will see the following contents:

Images
Volume 1 Book
Volume 2 Book
Copyright.txt
Eckel.htm                 [this is the file you are now reading]
EckelCode.zip

Mr. Eckel's text is found in the "Volume 1 Book" and "Volume 2 Book" folders while his code is found in the EckelCode.zip file. The EckelCode.zip file is a standard .ZIP file which holds all of Mr. Eckel's .CPP and .H files along with their accompanying .MAK and .PRJ files for all of the example programs in the Thinking In C++ books. You can use any .ZIP file utility (such as WinZip) to unpack this .ZIP file. You can choose any destination for the unpacked contents (maybe, C:\Eckel or C:\Computer Science Lab\CppIde\Eckel). Once the EckelCode.zip file has been unpacked to your hard drive you are ready to open Mr. Eckel's example programs from CPPIDE.

Let's assume that you decide to unpack the contents of the EckelCode.zip file to the location "C:\Eckel". If you then use Windows Explorer to take a look at this new folder you will observe the following folders and files:

V1
V2
Copyright.txt
RevisionHistory.txt

If you proceed into the V1 (volume 1) folder you will find:

C02       [there are no example programs in Chapter 1]
C03
C04
...
C16
Copyright.txt
require.h
RevisionHistory.txt

If you proceed into the C02 folder you will find 12 project folders holding the 12 example programs demonstrated in Chapter 2 of Eckel's Volume 1.

There are a total of 257 example programs in Volume 1 of Thinking In C++ and another 308 example programs in Volume 2.

I had to make minor changes in some of these example programs due to how I reorganized the source files into individual folders for each project. Generally I only had to modify directory paths because while Mr. Eckel's convention is to keep all of the example programs for each chapter in a common folder, CPPIDE requires that each program have a unique folder (this is required by CPPIDE so each program can provide both a Debug build and a Release build).

I had to make a few other changes to get some of the example programs to compile with the latest version of the MinGW port of the Gnu C++ compiler (the compiler used by CPPIDE). An example of this type of change was in the ExtractCode program from Volume 2 Chapter 3 where I had to modify the number of parameters passed to the mkdir() library function.


These remaining notes are intended to ease your transition from my C++ curriculum to that of Mr. Eckel. My philosophy in preparing an introduction to C++ was to minimize the complexity level by highlighting only the most critical aspects of the language. Mr. Eckel's materials are more intended for experienced programmers who are transitioning to C++ from a different language. His emphasis is on demonstrating each and every language feature, including the most arcane and trouble-some features. This is commendable work, but it means tough sledding in places for novice readers.

Don't let yourself get discouraged if you bog down in certain sections of this book. Mr. Eckel proceeds from topic to topic without letting you know which ones you will use in 90% of your programs and which ones even the experts have trouble with. I didn't make it through Chapter 8's treatment of the myriad complexities and inconsistencies associated with the "const" keyword before I was thoroughly disgusted with the C++ language. But you don't need to be an expert in all areas of the C++ language (an immense undertaking) before you can use its best features to write really impressive programs.

Many of Mr. Eckel's example programs don't do anything other than compile. That is, many of his programs don't interact with the operator or print anything to the screen. Some don't even compile. As an example of this, the FileStatic program in Chapter 3 produces the compile error "undefined reference to fs". Seeing this compiler error message is the whole point of that example program. As another example, the Stack2 program in Chapter 5 consists only of a single .H file and hence can't possibly compile (in the end-of-chapter exercises Mr. Eckel assigns you the job of adding the necessary .CPP files). Others don't work as intended but are presented to demonstrate pitfalls. For example, the OnTheFly program in Chapter 3 prints out smiley faces. To make this program work as intended you need to change the statement:

while(char c = cin.get() != 'q')

to:

char c;
while((c = cin.get()) != 'q')

Furthermore, to get the "snap, crackle, pop" part of this program to work correctly you have to add:

cin.get();

just prior to:

cout << "Type A, B, or C" << endl;

My recommendation for reading the Thinking In C++ book is to scan the first half of the first chapter without getting too concerned if you don't understand all the lingo. You basically need to have struggled writing complex programs in previous programming languages to appreciate the innovations of the C++ language. And I would skip the second half of the first chapter and come back to it later.

The first half of the second chapter concerns the process of compiling and linking a program to produce an executable. You don't need to be an expert on these topics since I have provided the makefiles that encapsulate the necessary recipe. All you need to do to compile one of Mr. Eckel's programs is to click on the "Compile" button on CPPIDE's toolbar.

You get to the first example program in the second half of the second chapter. All of Mr. Eckel's programs are console-mode programs meaning that they will interact with the user via text in a "DOS box" window. Whereas I favor using the C language's printf() function to produce console-mode output, Mr. Eckel favors using the cout class which is defined in the iostream.h header file.

Mr. Eckel employs a convention in all his programs (his .CPP files) that allows another program to analyze his source code and extract documentation from it. The trick involves specially formatted comment lines. The compiler ignores anything on a line after a double forward slash so the following two lines are totally ignored by the compiler:

//: C02:Hello.cpp
///:~

However this other program can identify these specially formatted comment lines and use them as signposts that identify significant items such as the name of the file. The Java language has defined a standard way of doing this which is similar to what you see here.

Mr. Eckel anticipated that you would compile and run his example programs from the command line, which on a Windows computer means you would employ the DOS box (Start/Programs/MS-DOS Prompt). However CPPIDE shields you from the command line by offering toolbar buttons for compiling and executing all programs.

Some of the example programs require command line parameters. The first such program is the CommandLineArgs.cpp program shown in Chapter 3. 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:

CommandLineArgs first second third

When you initiate a console-mode program from 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. The full list of Eckel example programs that require command line arguments is shown below:

CommandLineArgsChapter 3
ArgsToIntsChapter 3
FloatingAsBinaryChapter 3
DynamicDebugFlagsChapter 3
StackTestChapter 4
Stack3TestChapter 6
ErrTestChapter 9
Stack4TestChapter 9
LineNumChapter 11
OStackTestChapter 15
TStackTestChapter 16
HTMLStripperVolume 2 Chapter 3
ExtractCodeVolume 2 Chapter 3
CppCheckVolume 2 Chapter 4
HTMLStripper2Volume 2 Chapter 4
ShowErrVolume 2 Chapter 4
FindBlanksVolume 2 Chapter 6
SortedSearchTestVolume 2 Chapter 6
DequeConverterVolume 2 Chapter 7
DequeOverflowVolume 2 Chapter 7
FEditTestVolume 2 Chapter 7
IndexingVsAtVolume 2 Chapter 7
MultiSetWordCountVolume 2 Chapter 7
StringDequeVolume 2 Chapter 7
StringVectorVolume 2 Chapter 7
TokenIteratorTestVolume 2 Chapter 7
VectorOverflowVolume 2 Chapter 7
WordCountVolume 2 Chapter 7
WordListVolume 2 Chapter 7
WordList2Volume 2 Chapter 7
WordSetVolume 2 Chapter 7
DeadlockingDiningPhilosophersVolume 2 Chapter 11
FixedDiningPhilosophersVolume 2 Chapter 11
Interrupting3Volume 2 Chapter 11

In Chapter 4 Mr. Eckel begins putting functions inside structs, using only the capabilities found in the C language. His intent is to demonstrate the thought process that led to the C++ language. However this example program might overwhelm a beginner. In Chapter 6 Mr. Eckel will re-implement this same functionality using the class feature of the C++ language and that program will actually be a lot easier to read (what a great advertisement for the C++ language).

Some of the example programs (especially in Volume 2) 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.

Thinking In C++ Volume 1 Errata

Chapter 2's title appears at the very bottom of chapter 1 rather than at the start of Chapter 2.

In Chapter 2 you find:

To add a brand-new element on the end of a vector, you use the member function push_back( ). (Remember that, since it’s a member function, you use a ‘.’ to call it for a particular object.)

Mr. Eckel says "remember" but he doesn't introduce the '.' notation (the member selection operator) until Chapter 4.

Mr. Eckel's description of his OnTheFly.cpp program in Chapter 2 might give you the wrong impression regarding the i variable defined within the following for loop:

for(int i = 0; i < 100; i++) {
    q++; // q comes from a larger scope
    // Definition at the end of the scope:
    int p = 12;
}

Mr. Eckel says, "The scope of i is the scope of the expression controlled by the for loop, so you can turn around and re-use i in the next for loop." Mr. Eckel is not trying to say that the i variable is already defined and available for use in a subsequent for loop, such as the one shown below:

for(int i = 0; i < 100; i++) {
    q++; // q comes from a larger scope
    // Definition at the end of the scope:
    int p = 12;
}
for(i = 0; i < 100; i++) {
}

This code results in a compiler error, because the i variable is not defined in the second for loop. Mr. Eckel's statement is meant to indicate that since the scope of the original i variable ends at the closing brace of the first for loop, you can define another i variable in a second for loop as seen below:

for(int i = 0; i < 100; i++) {
    q++; // q comes from a larger scope
    // Definition at the end of the scope:
    int p = 12;
}
for(int i = 0; i < 100; i++) {
}

In Chapter 3 it is unfortunate that right after explaining unions Mr. Eckel says that arrays have the "variables stacked on top of each other". It would be better to say "placed consecutively in memory".

Eckel uses the term aggregate initialization to explain some code in Chapter 3 but he doesn't get around to explaining aggregate initialization until Chapter 6.

The NewHandler program in Chapter 13 does not compile. The Gnu g++ compiler complains that the use of the "count" variable is ambiguous.

The TPStashTest program in Chapter 16 compiles but has a bug. When run, it spits out an endless sequence of the last 2 messages shown below:

Removing 5 manually:
destroying[0]
destroying[1]
destroying[2]
destroying[3]
destroying[4]
Remove two without deleting them:
AutoCounter 5
AutoCounter 6
The destructor cleans up the rest:
...        [lines from TPStashTest.cpp]
destroying[7]
destroying[8]
destroying[9]
~CleanupCheck()
All AutoCounter objects not cleaned up
~CleanupCheck()
All AutoCounter objects not cleaned up
...

and then after a few minutes it crashes with a stack fault. It is clear that in the CleanupCheck destructor, the trace.size() function is returning the value 2 rather than the "required" value of 0, but I can't explain why this results in an infinite number of these messages.

Thinking In C++ Volume 2 Errata

In the Wrapped.cpp example program of Volume 2, Chapter 1 there is a member function (specifically the overloaded operator[ ] function) for the PWrap class which is declared as follows:

T& operator[](int i) throw(RangeError)

The notation seen in this function declaration is called an "exception specification". Mr. Eckel does not get around to introducing this notation for another 9 pages when he gets to his Unexpected.cpp example program.

The following Volume 2 programs will not compile with the latest MinGW port of the Gnu g++ compiler (this is the compiler used in CPPIDE). In many cases you can observe that the book authors are aware of this as they include the notation {-g++} in the comments at the start of the program.

The Covariance example program in Chapter 1 of Volume 2 lacks a main() function and hence couldn't possibly compile. Yet it is useful to compile what is there in order to see that the compiler correctly flags that the overriden version of f() defined by the Derived class illegally changes the exception thrown by the base class.

The following Volume 2 programs compile but crash.

The IosExamp.cpp program in Chapter 4 prompts you to "type any character" but won't terminate until you type ENTER.

The Ostring.cpp program in Chapter 4 prompts you to enter an int, float, and string but you need to enter these 3 things using spaces (blank chars) as your delimiter rather than commas.

The ImplicitCast.cpp and Lookup2.cpp example programs in Chapter 5 generate warnings from the compiler, but that's the point of these examples.

The CopyIntsFromFile.cpp program in Chapter 6 requires an input data file named "someInts.dat". One way to get an appropriate data file is to first run the CopyIntsToFile.cpp program, which produces a data file named "ints.out", and then rename this file and copy it to the other project folder.

Unless you specify a different input file via a command line argument, you will need to create a "test.txt" file before running the SortedSearchTest.cpp program in Chapter 7.

About 10 of the example programs from Chapter 7 cause the C++ compiler to issue the warning: "defines only private constructors and has no friends". I don't know if this was intentional on the part of Bruce Eckel but the programs do compile and run and evidently serve their intended purpose. In general you don't want to distribute programs that cause warnings from your compiler, but that gets very difficult when you port your programs, as Mr. Eckel has done, to multiple compilers.

The AmbiguousName.cpp example program in Chapter 9 will not compile. This is not an error: it is the whole point of this example.

The MulticastCommand example program in Chapter 10 runs until you type CTRL+C (i.e., hold down the Ctrl key simultaneous with the letter C).


Return to the Catalog of Programs