HPlogo HP C++ Programmer's Guide: HP 9000 Series Workstations and Servers > Chapter 1 Overview of HP C++

Getting Started with HP C++

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

This section briefly describes the use of the CC command to invoke HP C++, tells you how to compile and execute a simple C++ program, and explains how to access online sample programs.

Using the CC Command

To invoke the HP C++ compiling system, use the CC (uppercase) command at the shell prompt. The CC command invokes a driver program that runs the compiling system according to the filenames and command line options that you specify. See Chapter 3 “Compiling and Executing HP C++ Programs” for more details about the compiling system and the CC command.

Compiling and Executing a Simple Program

The best way to get started with HP C++ is to write, compile, and execute a simple program. The following is a simple program to get you started:

#include <iostream.h>
void main()
{     
      int x,y;
      cout << "Enter an integer: ";
      cin >> x;
      y = x * 2;
      cout << "\n" << y <<" is twice " << x <<".\n";
}

Compiling this example with CC produces an executable file named a.out. To run this executable file, just enter the name of the file. The following summarizes this process with the file named getting_started.C:

$ CC getting_started.C
$ a.out
Enter an integer: 7

14 is twice 7.

Debugging C++ Programs

You can debug your C++ programs with the HP Symbolic Debugger. You need to compile your program with the -g option first. For more information about the HP Symbolic Debugger, see the HP-UX Symbolic Debugger User's Guide.

Using the Online Sample Programs

Many of the C++ programs from this and other manuals are stored online for you to use and experiment with. The source files for these programs reside in the directory /usr/contrib/CC/Examples (/opt/CC/contrib/Examples/bank_ex for HP-UX 10.x C++ versions).

© Hewlett-Packard Development Company, L.P.