WARNING: 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:
Code: Select all
#include <iostream.h>
--------------------------------------------------------------------------------
Listing 1.1. HELLO.CPP, the Hello World program.
Code: Select all
1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }
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 twice. 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 the above. 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 3. You will need to add this line before the beginning of the main function in every program in this book. Most compilers don't require this, but a few do.
Your finished program will look like this:
Code: Select all
1: #include <iostream.h>
2:
3:
4: int main();
5: {
6: cout <<"Hello World!\n";
7: return 0;
8: }
Code: Select all
Hello World!