C++ Compilers and IDEs
Prof. Edward F. Sowell
Compilers You Can Use

There are several options when choosing a C++ compiler and development environment for Computer Science courses. Among these are:

All of these should be available in the CS 200 Lab. Check at the campus bookstore for special student prices on the Microsoft and Borland products. The GNU product is free from the Internet.

Of these choices, I prefer the Microsoft product. I believe it is the most widely used in the Department and in industry.

You should try to get the latest version of whichever compiler you choose. The primary difference between recent versions is the degree to which they comply with the ever-changing C++ standards. For example, Visual C++ 6 supports the C++ Standard Library, whereas version 5 does not. The practical implication is that the examples in current texts, such as Deitel & Deitel C++, 3rd edition, will not run without changes if you use Visual C++ 5, but they will for version 6. On the other hand, the changes needed to make them work are small (compare the "Hello World" programs for Visual C++ and Borland C++ below). Unless your course is focusing on use of the Standard Library, an older version may do.

Compilers You Can Not Use

You should not use the older, DOS-based compilers such as Borland Turbo C++. The primary reason is that they generate 16-bit code, which limits the size of arrays and other data structures. Consequently, higher level courses will be using the newer 32-bit compilers listed above.

Integrated Development Environments (IDEs)

In the old days, programmers worked entirely at the command line. However, today many prefer more modern tools with graphical user interfaces (GUIs) for development, often called Integrated Development Environments (IDEs). Visual Studio is an example of an IDE, and Borland provides a similar product as part of its recent C++ offering. The purpose of such tools is to make it easier to develop computer software applications. They allow you to:

all from within a single environment.

Without an IDE, you have to:

While IDEs may seem overly complex to beginners, once you use one for a while the complexity seems to fade. They are especially useful when you are working with larger projects with many source files.

Note: An older alternative to the IDE is the "make" program. Make provides automation of the command line steps outlined above. While many still prefer the make approach, programming professionals are increasingly switching to the ever improving IDEs.

General Rules when Using IDEs

The Console Target Application There are several "target application types" you can create. For the simple programs students typically write in programming classes, the "Console Application" is probably the best target application type. A Console Application runs in a "DOS box." That is, when the application is executed an MS DOS window is automatically opened on the Windows desktop and the program begins to execute. It is called a Console Application because this is reminiscent of pre-Windows times when the entire screen was devoted to the single executing program. Because you don’t have to worry about opening and closing windows for you output on the screen, Console Applications are much easier to deal with than the full Windows Applications with which you are most familiar. Where to Put Your Projects and Files One consequence of using IDEs is that a typical project, even for a very modest program size, will consist of many files and use a lot of disk space. For this reason, as well as slow floppy access speed, you do not want to work directly from a floppy disk when using an IDE. You should always create projects on the hard disk. If using a computer other than your own, such as CS200 Lab computer, you can transfer your source files from your floppy when you begin work, and back to the floppy afterwards.

Moreover, you should specify exactly where you want the project to reside on the hard disk, rather than taking the default directories offered by the IDE. Otherwise, you will find yourself not knowing where your files are! A large portion of the problems students typically have with IDEs are caused by not following this rule.

Moving between Computers Unless you do all of your programming work on a single machine that you alone have access to, you will need to move your work from one machine to another. The best way to do this is first "clean" your project directories on the hard disk, then copy them to a floppy. The cleaning process is to remove all files that are automatically created when the project is built. Among those that you can safely delete are the object code files (.obj) and executable files (.exe). In addition, for simple projects you can get away with deleting many other auxiliary files created by the IDE, as they will be automatically recreated when you reopen the project. The following table shows the files that can be safely deleted as well as those to keep for the visual and Borland IDEs:
Compiler Files to Delete Files to Keep
Visual C++ *.obj, *.exe, .ncb, .opt, .plg *.cpp, *.h, *.dsw, .dsp
Borland C++ *.obj, *.exe, .csm, .ilc, .ild, .ilf, .ils, .tds *.cpp, *.h, .ide

Once you have cleaned your project directory, copy what’s left, along with the directory, to your floppy. If you want, you can use WinZip or similar tool to not only compress the files so they take up less space on your floppy, but also copy the entire directory structure at once. Be sure to ask WinZip to save the directory information. Once copied to the floppy, you can delete the directories entirely from the hard disk. Note: The latter is very important if you are working on a Lab computer. Otherwise, someone else can copy your work.

To restore your project, copy the files from the floppy to the hard disk, using the same directory structure. If you used WinZip, just extract all the files into the desired directory on your machine, using the "extra folder information." Then click on the project file, i.e., myProject.dsw for Visual C++ or myProject.ide for Borland C++. Rebuilding all will put you right back where you left off!

Creating a Project with Visual Studio

Note: Visual C 5 is described here. Version 6 is slightly different.

Note: See Deitel's Getting Started document too.

To create a simple "Console Application" you need to carry out the following steps:

  1. Execute the Visual Studio (Click on its Icon). In the CS 200 Lab, you will find this icon in a folder called VC6)
  2. Click Files on the top menu bar, then click New, and then click the Projects tab.
  3. Select Win23 Console application
  4. In the Location field in the left panel, type the directory where you keep all your projects for a particular course, e.g., C:\cc223v.
  5. In the Project name field in the left panel, type a unique name for the project you are creating, e.g., Exer1_15. Click OK. This creates a project with no files.
  6. To add a main program file, click Project; select Add to project, and New. Click on the Files tab if not already selected. Under files tab, select C++ source file. In the File name field, type a name for the file, e.g., main, or exer1_16. Click OK.
  7. In the left panel, select the Files view tab at the bottom. This will display the project as a tree of files. To see the files, expand the tree by clicking the +. You will see only the file just added. Click on tat file. This displays the file in the right panel. It is empty.
  8. Type you program into the right panel, e.g.,

  9.  

     
     
     
     
     
     
     
     
     

    // My first C++ program
    #include <iostream>
    int main()
    {
    std::cout << "Hello World!" << endl;
    return 0;
    }

    After it is typed, save it with Save from the Files menu, (File|Save).

    Note: The Microsoft 6 compiler supports the C++ Standard Library, and there is a std namespace. For this reason we must add the std:: prefix on the cout and endl. Unlike the Borland product, the console application created by Visual Studio does not automatically close the DOS-box when the program completes; instead, it presents a "Press any key to continue" message.

  10. To build the project, i.e., create the target console application, click on the Build menu, and select the Build <targetName> choice, where <targetName> is the name you choose for the project. This will compile, and link your console application. The output panel at the bottom of the visual Studio window will show the progress, as well as any errors that may be discovered.
  11. If no errors were reported, you can execute the application by clicking Build|Execute <targetName>. This will cause an MSDOS box to open, in which the program output will appear.
  12. If errors were reported, click on the first error in the output screen. This will select the offending line in the source file in the right panel. Fix the error and repeat from step 9 above.
Creating a Project with the Borland IDE

Note: Borland C++ 5 is described here. Later versions may be slightly different.

To create a simple "Console Application" you need to carry out the following steps:

  1. Execute Borland C++(Click on its Icon). In the CS 200 Lab, you may find this icon in a folder called Compilers.
  2. Click File on the top menu bar, then click New, and then Project.
  3. Select Win23 under Platform and Console under Target model.
  4. In the Project path field type the full path and name for your new project. It’s a good idea to make it a subdirectory of a directory where you keep all your projects for a particular course, e.g., C:\cc223v\myFirstProject. As you type in the path, the Target name field is automatically filled with a default name of the last item in the path, e.g., myFirstProject. Accept this default.
  5. Before leaving the New target dialog, click on Advanced button at the left. Make sure only the ".cpp node" is selected in the Advance dialog. Click OK on the Advance dialog, then OK to leave the New target dialog. This creates your new project, shown as a tree in a new window. The project will have a single file, myFirstProject.cpp, shown as a node in this tree.
  6. In the Project window, click on the .cpp file. This displays the file in a new window. It is initially empty.
  7. Type your program into the empty file window, e.g.,

  8. // My first C++ program
    #include <iostream>
    #include <conio.h>
    int main()
    {
    cout << "Hello World!" << endl;
    cout <<"Press any key to continue" << endl;
    while (!kbhit());
    getch ();
    return 0;
    }

    After it is typed, save it with Save from the Files menu, (File|Save).

    Note: The Borland 5 compiler does not support the C++ Standard Library, and there is no std namespace. For this reason we omit the std:: prefix on the cout and endl. The while (!kbhit()); getch (); and #include <conio.h> are to keep the console application from automatically closing the DOS-box when the program completes. Otherwise, you would not be able to see the results.

  9. To build the project, i.e., create the target console application, click on the Build menu, and select the Make all choice. This will compile, and link your console application. The Message panel at the bottom of the IDE window will show the progress, as well as any errors that may be discovered.
  10. If no errors were reported, you can execute the application by clicking Debug|Run This will cause an MSDOS box to open, in which the program output will appear.
  11. If errors were reported, click on the first error in the output screen. This will select the offending line in the source file in the right panel. Fix the error and repeat from step 8 above.