Sams Teach Yourself C++ in 21 Days

(singke) #1
Getting Started 19

1


Getting Started with Your Compiler ......................................................................


This book is notcompiler specific. This means that the programs in this book should
work with anyANSI-compliant C++ compiler on any platform (Windows, Macintosh,
Unix, Linux, and so on).
That said, the vast majority of programmers are working in the Windows environment,
and the vast majority of professional programmers use the Microsoft compilers. The
details of compiling and linking with every possible compiler is too much to show here;
however, we can show you how to get started with Microsoft Visual C++ 6, and that
ought to be similar enough to whatever compiler you are using to be a good head start.
Compilers differ, however, so be certain to check your documentation.

Building the Hello World Project ....................................................................


To create and test the Hello World program, follow these steps:


  1. Start the compiler.

  2. Choose File, New from the menus.

  3. Choose Win32 Console Application and enter a project name, such as hello, and
    click OK.

  4. Choose An Empty Project from the menu of choices and click Finish. A dialog box
    is displayed with new project information.


Using the Standard Libraries
If you have a very old compiler, the program shown previously will not work—the new
ANSI standard libraries will not be found. In that case, please change your program to
look like this:
1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << “Hello World!\n”;
6: return 0;
7: }
Notice that the library name now ends in .h(dot-h) and that we no longer use std::in
front of couton line 5. This is the old, pre-ANSI style of header files. If your compiler
works with this and not with the earlier version, you have an antiquated compiler. Your
compiler will be fine for the early days of this book, but when you get to templates and
exceptions, your compiler might not work.
Free download pdf