|
|
|
|
|
|
|
or printing to the screen. A class is a collection of data and related functions; I'll be talking about classes a lot. |
|
|
|
|
|
|
|
|
The steps to create an executable file are: |
|
|
|
|
|
|
|
|
1. Create a source code file, with a .cpp extension. |
|
|
|
|
|
|
|
|
2. Compile the source code into a file with the .obj extension. |
|
|
|
|
|
|
|
|
3. Link your OBJ file with any needed libraries to produce an executable program. |
|
|
|
|
|
|
|
|
If every program worked the first time you tried it, that would be the complete development cycle: write the program, compile the source code, link the program, and run it. Unfortunately, almost every program, no matter how trivial, can and will have errors, or bugs, in it. Some bugs will cause the compile to fail, some will cause the link to fail, and some will only show up when you run the program. |
|
|
|
|
|
|
|
|
Whatever the type of bug you find, you must fix it, and that involves editing your source code, recompiling and relinking, and then rerunning the program. This cycle is represented in Figure 1.1, which diagrams the steps in the development cycle. |
|
|
|
|
|
|
|
|
HELLO.CPPYour First C++ Program. |
|
|
|
|
|
|
|
|
Traditional programming books begin by writing the words Hello World to the screen, or a variation on that statement. This time-honored tradition is carried on here. |
|
|
|
|
|
|
|
|
Type the first program directly into your editor, exactly as shown. After you are certain it is correct, save the file, compile it, link it, and run it. It will print the words Hello World to your screen. Don't worry too much about how it works; this is really just to get you comfortable with the development cycle. Every aspect of this program will be covered over the next couple of days. |
|
|
|
|
|
|
|
|
The following listing contains line numbers on the left. These numbers are for reference within the book. They should not be typed in to your editor. For example, in line 1 of Listing 1.1, you should enter: |
|
|
|
| |
|
|