Part 1. Configuring a New Application

Before you begin writing code, you need to provide some information so that VisualAge C++ can configure your program's build environment properly. In this section, you will use the VisualAge C++ Integrated Development Environment (IDE) to do the following:

This section should take you approximately 30 minutes to complete. You will learn to perform the following IDE tasks:

Create a Project and Add Files to It

Follow these steps to create your project:

  1. Start the VisualAge C++ IDE.
  2. Choose to create a new project in one of the following two ways:
  3. The Project SmartGuide will guide you through creating the project.
  4. In the Project SmartGuide, click the Next button if you are not already at the Project Configuration screen of the SmartGuide.
  5. Specify review.icc as the project name. If you do not enter the file-name extension .icc, the SmartGuide will add it for you.

    The .icc file is the configuration file for a project. It is similar to a makefile in that it contains a list of the source files and target executables for a project, along with options used to build the application.

  6. Specify a directory in which to store the project files. For example, if you  want to store the tutorial project files on drive F:, you might enter F:\vatutor as the directory.  If the directory you specify does not exist, it will be created for you.

    For the remainder of this tutorial, wherever you see the path F:\vatutor, you can substitute the path you specify in this step.

  7. Click Next. The Target Type screen appears. On this screen you add targets to your project. Make sure Executable(EXE) file is the current selection in the New target field, and click Add target.
  8. The Target SmartGuide appears. The Target SmartGuide guides you through defining your target. Click the Next button until you get to the Target Name screen.
  9. On the Target Name screen, enter the name and destination directory for your target. For the CGI example, name your target review.exe and specify the target directory as the directory from which CGIs run on your web server.
  10. You can also select a program type for your application, which predefines certain compiler and linker options. In the Program Type column, select WIN IOC or OS/2 IOC depending on your operating system. These two choices set project options so that your project can use IBM Open Class Library classes and member functions.
  11. Click Next to go to the Parts Type screen. Do not add any parts, because you will not be creating any visual or data access parts for this tutorial. (A separate tutorial section, Develop a Graphical User Interface from a Visual Part, teaches you how to work with visual parts. Information on data access parts is available in the online help starting at Data Access Builder.) Click Next again to go to the Source Files screen.
  12. The Source Files screen helps you create the part of the configuration file that specifies which source files are used to build the target. Enter the source file name main.cpp in the Files to Add or Create text entry field (remove any current path information from that field). Select the Relative Path check box, so that the files you add are placed in the default directory for your project. Then click Add>>.
  13. The SmartGuide asks if you want the file to be created. Click Yes. An empty main.cpp file is created.
  14. Click OK to close the Target SmartGuide and return to the Target Type screen of the Project SmartGuide.
  15. You will see the target you just defined in the list at the bottom of the Target Type screen. Click Next. The last Project SmartGuide screen lets you specify help files. Since you will not add help files for this exercise you can close the Project SmartGuide by clicking the Finish button.
  16. When the IDE asks if you want to open the project, click Yes.
  17. When the IDE asks if you want to build the project, click Yes.

You will encounter a build error, because you have not yet coded a main function for your program. A Help Tips error dialog will appear if you have not encountered a build error before. If the dialog appears, click OK to go to the Messages pane. If no dialog appears and you are not automatically taken to the Message pane, click the tab for the Project section and open the Messages page.

Add a Simple main Function to main.cpp

  1. Make sure that the Project section of the workbook is selected.
  2. Select the Source Files page.
  3. Select the main.cpp object for the main.cpp source file in the Source Files view in the upper left pane. Notice that when you select this file, the source view underneath changes to display the content of main.cpp, which is currently empty.
  4. Click anywhere inside the Source view. Enter the following code for main into it. If you are viewing the tutorial online, copy the code from your browser window and paste it into the Source view.

    Note that all comments shown in this and other source code in the tutorial are for your information; you do not have to type them in. Also, code is colored in this tutorial to reflect the colors you will see in Source views within the IDE.

    #include <fstream.h> // for use of cout statement (and file i/o later)
    
    int main() {
       cout << "Content-Type: text/plain\n\nHello world!" << endl;
       return 0;
    }
    Implementation Details: The output begins with a header ("Content-Type: text/plain\n\n"), which is the CGI header that instructs a user's browser to display the subsequent text as plain unformatted text. This header will display when you run the program from a command shell, but will not display when you start the program from a browser.

Your project is now ready to build.

Build and Run Your Program

Now that you have added content to your source file, you can build and run the project.

  1. To start the build, click the Build button () on the toolbar or press Ctrl+Shift+B. The IDE automatically saves any files you have opened and added to the project, then starts building the project.
  2. If any errors occurred during the build, the Messages page appears. (If it does not appear, but the status area indicates build errors, go to the Messages page in the Project section.) Select the error in the Messages pane; the view below this pane shows the source code for the object containing the error, with the cursor on the line containing the error. Correct any source code errors, then build again.
  3. You can run your project from a command shell or from a web browser on your workstation:
  4. If you ran the program from the command shell, you will see:
    Content-Type: text/plain
    
    Hello world!

    If you ran the program from a web browser, the browser interprets the Content-Type header, and displays only the text Hello world!

You can now proceed to the following parts of the tutorial:

You may also want to explore some of the IDE concepts in more detail. You can read the following topics in Tour the VisualAge C++ IDE if you have not done so already. Each topic should take you five minutes or less.