Frequently Asked Questions
for
C++ for Dummies, 4th Edition

Q: I understand that C++ for Dummies assumes some knowledge of C programming. Is this true?
A: The current edition, the 4th edition, does not assume that the reader has any experience with C. 4th edition "begins at the beginning", as they say.

Q: I've tried to install the DJGPP environment, but I can't seem to get it work? (Sometimes this takes the form of error messages like a stream of error messages to the effect that the compiler can't find library files.) What am I doing wrong?
A:The fifth edition of C++ for Dummies used the Dev-C++ compiler/environment which doesn't suffer from these problems; however, the fourth edition and earlier of C++ for Dummies was written using the DJGPP environment since it is based on the high quality, Freeware GNU compiler.

Unfortunately, DJGPP has not kept up with the times. The DJGPP GNU compiler does not work well with later versions of Windows. In addition, DJGPP is difficult to install. Fortunately, another GNU based package is available to take its place.

I strongly suggest that readers switch over to the Dev-C++ compiler. Dev-C++ is:

Follow these steps to install Dev-C++:


Figure 1 Enable exceptions


Figure 2 Include debugging information in the final executable file

Q: What else do I need to do to use the Dev-C++ environment with the programs in the book?
A: Dev-C++ adheres to the ISO C++ standard more closely than the DJGPP compiler did. You will need to adapt the programs in 4th and earlier editions of the book to the following template:

//
// Template - provides a template to be used as the starting
// point
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    // your C++ code starts here

    // wait until user is ready before terminating program
    // to allow the user to see the program results
    system("PAUSE");
    return 0;
}

Q: I get a stream of error messages to the effect that the compiler can't find library files. What am I doing wrong? (Notice that your program may have worked on earlier versions of C++, such as Visual C++ 6.0.)
A:The ISO standard specifies that library functions are contained in the "std" namespace. Most versions of C++ assume the use of std automatically; however, C++ compilers that adhere strictly to the standard do not. In that case, add the following to the beginning of your .cpp source code module:

using namespace std;
The "using" statement is part of the standard template above.

Q: My program seems to exit before I can see the final output.
A: Adapt your program to the standard template above - this should fix you right up.

Q: I've tried executing the GNU installation script that comes on the CD-ROM.
A: Early versions of the book came with a batch file that attempted to install the GNU package. This installation program had an error that results in an incorrect installation. (The installation program originated from the publisher so I had no control.) Remove the DJGPP directory and install the package manually as described in the book (and later on in this FAQ).
Alternatively, download Dev-C++ as described earlier.

Q: I want to stay with the DJGPP environment; I've tried to install the DJGPP C++ package manually using the instructions in the book (or in the README file, but I can't seem to get it work?
A: Instructions for installing the compiler are included within the book (these instructions must be modified slightly for WinME and Win2000 and later - see below). Some readers have complained that the instructions are not clear so let me try again (these instructions are intended to do exactly the same thing as the earlier instructions):

  1. create the directory c:\DJGPP (this is explained in greater detail below if you confused)
  2. copy of of the GNU .zip files into that directory
  3. unzip them all (the executables will going into \DGJPP\bin, the \DJGPP\include for include files, etc. the DJGPP directory itself should having nothing but DJGPP.ENV (maybe one other file, but it's not important)
  4. add c:\DJGPP\bin to your PATH and add the SET DGJPP c:\DJGPP\DJGPP.ENV to autoexec.bat (as explained in further detail).
  5. Reboot.

Q: What do you mean by "edit the autoexec.bat file"? How do I do that?
A: The autoexec.bat file is a file in the root directory c:\ that executes when the computer boots up. Use the following steps:

  1. 1) Open an MSDOS window (Start|Programs|Accessories|MSDOS Prompt)
  2. Go to the root directory (enter "CD \")
  3. Open autoexec.bat in an editor (enter "Notepad autoexec.bat")
  4. Navigate to the bottom of the file (scroll down and click on the last line of the file)
  5. 5) Type the lines:
  6. Save the file ("File|Save")
  7. Exit ("File|Exit")
  8. Close the Window (click on the close button in upper right hand corner of the window)
  9. Reboot.

Q: What do you mean "create a directory"? How do I do that?
A: It may help to know that a "directory" is the same thing as a "folder". If this doesn't help, then use the following steps:

From Windows:

  1. start with the MyComputer icon on the desktop.
  2. double click on MyComputer, then Local Disk(C).
  3. right click in the window that opens up
  4. click on File->New
  5. select folder
  6. type in the name DJGPP (this renames the folder from "New Folder" to "DJGPP")
  7. You're done!

Q: You ask me to "unzip" the files contained on the CD-ROM. What does that mean?
A: The ZIP format is a long time favorite protocol for combining a number of files and compressing the result. If you do not already own and unzipper, check one of the download sites (such as ZDNET.COM) and search for WinZIP. Download and install WinZIP. The instructions for how to use it are included in the package. (I encourage you to pay for WinZIP as it is a first class product.)

Q: Wait a minute... when I unzipped the files from the CDROM I ended up with a bunch of files in \DGJPP but no \DGJPP\bin or any other subdirectories. What's wrong now?
A: This is probably because you unzipped the files "flat" meaning that your unzip placed all of the files in the "current" directory and did not create the intended directory hierarchy.

In WinZip, make sure that the "Use Folder Names" is clicked on as shown here.

Double click on one of the ZIP files. Now select Actions-Extract. Click Use Folder Names on if it isn't already. Now click Extract.
Note that you only have to update this setting once - it stays in effect until specifically clicked off.

Q: I am using the WindowsME operating system and the installation procedure doesn't work?
A: The Autoexec.bat and Config.sys files are no longer available during start up on WindowsME. This makes the instructions on page 14 of this book incompatible with ME.

In order to set the environment variables you must go through System Configuration Utility ( Start - Programs - Accessories - System Tools - System Information - Tools - System Configuration Utility). Click the environment tab. Update the PATH environment variable to include c:\djgpp\bin (it should end up being something like "c:\windows;c:\windows\command;c:\djgpp\bin"). Now add the DJGPP environment variable and set it to c:\djgpp\djgpp.env. Save these settings - Windows ME will force you to reboot.

Alternatively, you can just download Dev-C++ from www.bloodshed.net as explained above.

Q: I am using the Windows 2000 or Windows XP (or later) operating system and the installation procedure doesn't work?
A: Windows 2000/XP also don't use the Autoexec.bat and Config.sys files. You will need to edit the autoexec.nt file found in c:\windows\system32 instead.

As always, you can just download Dev-C++ from www.bloodshed.net as explained above.

Q: I am using the Windows NT operating system. I can install everything, but I still get the can't find iostream.h message.
A: The MS-DOS window in Windows NT does not support long filenames. It expects files to be in the DOS 8.3 format. The GNU people say that everything works just fine if you unzip the .zip files using PKUNZIP (this older unzipper chops off long filenames to 8 chars.

  1. Downoad PK250DOS.EXE (or a version of PKZIP designed for MSDOS). You can find PK250DOS.EXE in the ZDNET Download Library or from PKWare, the company that created PKZIP. When asked, store this file into a temp directory..
  2. Open a MS-DOS window. CD to the temp directory and execute PK250DOS.EXE. This self-extracting file will create a number of files including the unzip utility PKUNZIP.EXE.
  3. Create the DJGPP directory with the ZIP files following the instructions above.
  4. Unzip each of the .ZIP files from the CD-ROM using the following command (the following is just an example of one such command):

    pkunzip -d bnu281b.zip

    (The -d means retain the directory structure stored in the ZIP file. This is critical.)

I haven't been able to test this out but the GNU experts claim this works. See //www.delorie.com/djgpp/ for more details.

Q: I copied the source files from the CD-ROM over to my hard disk. When I open one of the .cpp files using rhide, it warns me that the file is "Read Only". Sure enough I get an error message when I try to save the edited file.

A: A file stored on a CD-ROM is flagged as ReadOnly (i.e., the ReadOnly flag is set). The ReadOnly stays set when the file is copied over to the hard disk. This keeps you editing the file. You have two options:
a) Save the source file off with a different name and proceed on. For example, you can open Conversion.cpp and save it back as Conversionx.cpp. The new file will not be ReadOnly.
b) You can reset the ReadOnly flag. Right-mouse click on the file. A drop down list sould appear. Select Properties at the bottom of the list. Under the section label "Attributes", click the ReadOnly property so that the little box isn't checked. Click OK to close the window.

Q: I am having trouble building some of the examples in the book. I get some obscure message that GNU C++ can't find some file "strstream.h". I included "streambuf.h", but I never even heard of "streambuf.h". What gives?
A: Make sure that the LFN variable in your environment file to YES as in "LFN=Y". It should already be that way, but make sure:
look in the directory \djgpp. There should be a file called djgpp.env. Open this file with Word and look for a line which defines the environment variable LFN. If you cannot file LFN or if the line appears as LFN=N, then add/change the line to LFN=Y.

(LFN=Y is short hand for LongFileNames=Yes. DOS 5.0 and earlier only allowed for file names in the format .. This is the well known DOS 8.3 format. Setting LongFileNames to Yes tells GNU C++ to accept file names with (almost) any number of characters.

The file name "iostream.h" fits within the 8.3 format. The file name "streambuf.h" does not. Thus, with 8.3, short file names, GNU C++ is actually looking for the file "streambu.h". (You may not include "streambuf.h.h", but "iostream.h" does.)

(You can verify this by looking in the directory \djgpp\lang\cxx for the file "streambuf.h". Make a copy of this file and name it "streambu.h". When you try to compile now, the compile still won't work since some of the other files are long file names, but you shouldn't get THE SAME error message.)

Q: OK. I checked the DJGPP.ENV file and it looks fine. What now?
A: Perhaps GNU C++ can't find the djgpp.env file when it cranks up and therefor goes with the default (which is LFN=N). Make sure that the line: set DJGPP=x:\djgpp\dgjpp.env appears in you autoexec.bat file where 'x' is the boot disk (normally C: ).

Q: Everything seems to work until I try to build a C++ file which I wrote called "My Favorite File.cpp". GNU C++ does even seem to recognize my file.
A: GNU C++ cannot handle file names containing spaces. Rename the file "MyFavoriteFile.cpp" and it should work.

Q: I can start rhide just fine. I can compile and build an application in the "current" directory, but as soon as I use the File|Open feature to change directories, the build operation no longer works.
A: The File|Open command within rhide does not work properly if you attempt to open a .CPP file in a different directory (this appears to be a bug). From within the DOS window, CD to the directory containing the .CPP source file. Execute rhide from there. If you want to compile a .CPP in a different directory, you must exit rhide first.

Q: If I own one of the earlier editions of C++ for Dummies, should I buy the third edition?
A: No. Edition 3 was merely a reprint with some of the problems fixed and a new appendix added. Edition 3 adds some material concerning the final C++ standard; however, the changes are minor.

Q: What changes are there between the third and fourth editions?
A: There are significant changes instituted with the fourth edition. Earlier editions assumed some knowledge of C (it was felt that there was too much to C++ in order to learn the entire language with no background). The fourth edition makes no assumptions - it starts from the beginning. In my opinion, that makes it a better book. However, the two books share most of the same examples.

Q: I want to use my own editor instead of rhide (or rhide is just not compatible with my version of Windows). Can I just compile my programs by entering a command at the command line?
A: Sure. See the next question.

Q: I've tried to compile my files from the DOS command line. How do I do that?
A: To compile a program such as Conversion.cpp, first move to the directory containing the file (in this case Chap01). From the DOS command line enter the following:

gcc -g -c Conversion.cpp -o Conversion.o
gcc -o Conversion.exe Conversion.o -lstdcxx

Notice the two x's in 'stdcxx'. (Compiling from the command line is not for beginners and I don’t support it – there are just too many things that can go wrong.)

Q: What if I didn't find my question here?
A: You may send your question to the author's mailbox. If your question is a new one, it will be added to the FAQ; however, if it already listed above, your question will be deleted without comment.

 

Errata:

The following problems were noted in 4th edition:

Page 44
The second operation in Table 4-1 was adorned with an extra | during the editing process. This operator is actually != and not !=|.

Page 46
The operator && was converted to & & during the editing process (note the extra space).

Page 48
The second expression appearing at the top of the page should be: 123 = 102 * 10 + 2 * 101 + 3 *100.

The following problems were noted in 4th edition by a Mr. Moorehouse (I have paraphrased his comments a little bit:

Page 44
Line 1 paragraph 4 says "&" instead of "&&" as described in Table 4-1

Page 45
Line 1 paragraph 4 says "&" instead of "&&" as described in Table 4-1

Page 48
In the explanation of the decimal system, the powers of ten should be shown as superscripts, not subscripts.

Page 49, 2nd paragraph
You say "Four bits make up a byte." There are EIGHT bits in one byte; four bits make up a "nibble". (Author reply: Doh!)

Page 52
The third shaded area has in its last line "0x2" but with the "2" as a subscript; it should be a normal character as depicted in the text line below the shaded area

In the line "Try this test: was is 0x6 | 0x3?". The "was" should be "what".

same page
In the last shaded area on that page there is the statement

cout.setf(ios::hex, ios::hex);

while the second line of TEXT on the next page describes this as

cout.setf(ios::hex);

Author reply: both are correct since the second argument defaults to the same as the first argument; however, listing both versions without explanation is unnecessarily misleading.

Page 53, Second paragraph of text
You have "The program reads nArg1 and nArg2 from the keyboard ..." The values are already imbedded in the program; they are NOT read from keyboard input.

Page 55, first paragraph
Delete "who don't own dogs" --- this contradicts "and whether or not they owned a dog" later in the same sentence. It also does not match the structure of the example.

 The following problems were noted in 4th edition by a Mr. Krafka:

Page 67
In the grey box, the line
cout << "Negative numbers are not allowe\n";

is missing the 'd' in 'allowed'

Page 70
A small sample of the switch() statement demonstrates case 1, case 2, case 3 and default. case 1 and case 2 end in a break. case 3 should also end in a break. The default clause does not require a break (it's optional in this case).

 

Errata concerning System Requirements

Appendix A says 200Kb is needed for the C++ development environment. You state, "The source code from the book takes a minimal amount of disk space." True, but you neglect to mention that when the "Author" files are installed the binary files are included, and the 17.85MB thus required is hardly "minimal".

Author reply: Today, 18MB is still not considered big; however, you can get around the problem as follows. The executables generated by the GNU C compiler are much smaller than the files generated by the Visual C++ environment. My only suggestion is to copy the source .CPP file, play with it and then delete any files generated by the compiler.