< previous page page_15 next page >

Page 15
Make certain you enter this exactly as shown. Pay careful attention to the punctuation. The in line 5 is the redirection symbol, produced on most keyboards by holding the shift key and pressing the comma key. Line 5 ends with a semicolon; don't leave this off!
Also check to make sure you are following your compiler directions properly. Most compilers will link automatically, but check your documentation. If you get errors, look over your code carefully and determine how it is different from Listing 1.1. If you see an error on line 1, such as cannot find file iostream.h, check your compiler documentation for directions on setting up your include path or environment variables. If you receive an error that there is no prototype for main, add the line int main(); just before line three. You will need to add this line to every program in this book before the beginning of the main function. Most compilers don't require this, but a few do.
Your finished program will look like this:
1: #include <iostream.h>
2:
3: int main();
4: int main()
5: {
6: cout << Hello World!\n;
7: return 0;
8: }
Try running HELLO.EXE; it should write
Hello World!
directly to your screen. If so, congratulations! You've just entered, compiled, and run your first C++ program. It might not look like much, but almost every professional C++ programmer started out with this exact program.
Compile Errors
Compile-time errors can occur for any number of reasons. Usually they are a result of a typo or other inadvertent minor error. Good compilers will not only tell you what you did wrong, they'll point you to the exact place in your code where you made the mistake. The great ones will even suggest a remedy!
You can see this by intentionally putting an error into your program. If HELLO.CPP ran smoothly, edit it now and remove the closing brace on line 6. Your program will now look like Listing 1.2.

 
< previous page page_15 next page >

If you like this book, buy it!