next up previous
Next: What is Compiling and Up: hello Previous: hello


A first C++ program: hello.cc

Use your text editor to create the source program. Call the file hello.cc.

Copy the following lines.

  #include <iostream>
  using namespace std;

  int main()                       
  {                            
    cout << "Hello, world.\n"; 
  }

Be sure to get all of the punctuation right.

Then when you are satisfied that it is correct, save the file. Do not exit the editor yet, however. In your xterm window, compile it with the command

   g++ hello.cc -o hello
Be sure to include spaces exactly as shown. The command causes the program hello.cc to be compiled and linked. The result of this operation is placed in an executable file called hello. If you didn't specify the output file with the -o flag the compiler would call it a.out, which isn't very mnemonic.

If the compilation is unsuccessful, return to the emacs window and fix your program. Save your edits and then rerun the compilation.

When the compilation is successful, run your program with the command

   hello
You should see the message, ``Hello, world.'' printed on your screen.

When you are finished, exit the editor.



Subsections
next up previous
Next: What is Compiling and Up: hello Previous: hello
Carleton DeTar 2007-08-17