Creating, compiling, and running a sample program

Step 1: Log on to pegasus

  • Use your username and password to log on.

    Step 2: Start up the editor

  • We will use the editor emacs. To create or edit a file called hello.cpp, at the <pegasus> command prompt, type

    emacs hello.cpp

    and push ENTER of course. Your screen should look something like this:

    Step 3: Type in your program

  • Use the DELETE key to correct errors (the BACKSPACE key may or may not work properly in emacs). Use the arrow keys to move through the text. Here is the sample program:

    #include <iostream.h>
    void main() {
      cout << "Hello, world!" << endl;
    }

    Your screen should look like this:

    Step 4: Save the file and exit the editor

  • Use CONTROL-X CONTROL-S to save the file, and CONTROL-X CONTROL-C to exit.

    Step 5: Compile the program:

  • At the <pegasus> prompt, type

    g++ hello.cpp

    If there are no errors, the computer will return silently to the <pegasus> prompt. The executable file will be named a.out.

    Step 6: Run the program

  • At the <pegasus> prompt, type

    a.out

    The program will run and simply print out a message.

    Step 7: Log out

  • At the <pegasus> prompt, type

    logout