This short tutorial is intended to lead the reader through the basics of writing, compiling, linking and running simple console C++ programs using Microsoft Visual C++ 6.0.
Microsoft Visual C++ 6.0 needs a project folder in order to store most of the data related to the compilation and linking (object files, executables, resources, ...). Therefore, the first thing you will want to do is create a project, even if your source code is extremely simple. Here is how you will create your project:
- After having started Microsoft Visual C++ 6.0, Open the "File" menu, and select "New..." (You can also press the key combination Control + N instead) to bring up the "New" setup window, which is used by Microsoft Visual C++ 6.0 to launch all the Wizards dedicated to the creation of new files and resources.
- Select the tab labeled "Projects" to start the creation of your new project. Since we are experimenting on console C++ programs, select "Win32 Console Application" from the list.
- Give a meaningful name to your project, then browse to the hard disk location you want it to be stored to. Please take note that Microsoft Visual C++ 6.0 will take care of creating the project directory if it does not already exist.
- Click "OK" to validate your input, and start the project creation Wizard.
- Although you might find interesting to try out sample applications offered by the Wizard, we will in our present case be completely satisfied by an empty project. We will add files to it later.
- After having clicked the "Finish" button, you will get a summary of the project Setup. In this case, the summary is extremely short, as you would expect from an empty project. Click "OK" to proceed with the creation of the project.
- Default installations of Microsoft Visual C++ 6.0 should display a toolbar on the left hand side of the screen, offering you a class view (listing classes and global members of the project) as well as a file view (recapitulating the list of source files used by the project). If applicable, you might also get a Resource view tab on this toolbar, but this is not the case in our current project. If you don't see this toolbar, you can make it appear by selecting it from the "View" menu.
The project having been created, we will now start adding files to it. Microsoft Visual C++ 6.0 gives the possibility to add existing files to a project (Via the "Project" menu), but we will in our tutorial restrict ourselves to the creation of a new empty source code file. Here are the steps required to achieve this:
- Bring up the "New" setup window by selecting the "New..." option from the "File" menu (Or by pressing Control + N key combination).
- From the "Files" tab (Usually selected by default), select the list item labeled C++ Source file, then give it a meaningful name. If you have several active projects open, you can choose to which project the file should belong, by checking "Add to project" option and selecting the corresponding project. A new file can not be added to several projects at once. If you want to include a file to an additional project, you will have to use the file importation from the other project's "Project" menu.
- Once you have submitted your input by clicking the "OK" button, Microsoft Visual C++ 6.0 fires the source code editor, and updates the File view.
- Finally, type the content you wish into the file, using the editor.
- Select "Save all" from the "File" menu to save all the data related to the project. Please note that this step is done automatically before compiling the project (see next section for compiling instructions) if the project had not been saved already.
The following instructions work for most of Microsoft Visual C++ 6.0 projects, except rare exceptions. The "Build" menu is the place where you will find everything related to Compiling, Building and Running the program generated by your source code. Here are the steps to go through to achieve this:
- Open "Build" menu, then select Compile (Or use the key combination Control + F7). Please note that this will save all the modifications to project files before proceeding. This step is done automatically before building the project (see next step for building instructions) if the project had not been compiled already.
- If there have been not compilation errors, you can proceed to building step. Open "Build" menu, and select Build (Or press F7). Please note that this will compile the project if required, before proceeding to the building phase. This step is done automatically before running the resulting executable (see next step for running the executable), if it had not been built already.
- If Microsoft Visual C++ 6.0 did not report any building error, that means the program has been built successfully, and you can now start it from within Microsoft Visual C++ 6.0. To do so, open "Build" menu, and select Execute (or use the key combination Control + F5). Please note that this will build the program before proceeding, if it had not been built already. From this point on, Microsoft Visual C++ 6.0 will launch a command-line shell, and start running the program into it. You can set additional parameters (Command line parameters for example) for the program, using Project settings ("Project" menu, or Alt + F7).
- After having ran the program, Microsoft Visual C++ 6.0 will pause the execution until you press a key, so that you get the possibility to view eventual results before the execution window closes itself.
As a short summary for this section, simply note that it is usually enough to press Control + F5 to have Microsoft Visual C++ 6.0 sequentially save the project, try to compile it (it will alert on errors so that you can correct them before proceeding), try to build it (it will alert on errors), and finally run it.
Note: The resulting executable can be found in a "debug\" sub folder within project directory.
Finally, you can close project files using the "File" menu, and selecting the option "Close Workspace".
You might have to confirm your choice in a Dialog Box. However, this step is not mandatory since Microsoft Visual C++ 6.0 allows you to create new projects or to close the application while you have a project open in it.