How to use Visual C++ in the Microsoft Developer Studio
  1. Introduction
  2. Creating a Workspace
  3. Exploring the Workspace
  4. Entering and Running a Program
  5. The Runtime Window (program console)
  6. Saving Your Work to Floppy Disk and Deleting Your Project from the Computer
  7. Returning to Work on a Previously Created Project
  8. Creating a Second Project
  9. Notes on Managing the Source Code Editing Window
Introduction
The tutorial describes how a C++ program is created, compiled, linked and run using Visual C++. It also gives some pointers on managing your projects.
The Microsoft Developer Studio is a development environment for creating programs in a number of languages including Visual Basic, Visual C++, and Java. Avoid using any commands not associated with the Visual C++ language.
This tutorial assumes that the reader has a basic knowledge of the Windows 95 environment, including the concepts of files, folders (directories), disks and file copying.

Starting Developer Studio
From the Windows 95 Start menu, search for the item Microsoft Developer Studio:
This will bring up an interface such as is shown below in Figure A.

Figure A.

Creating a Workspace

To use the developer studio, you need to create a workspace. In this workspace, you will have a project and all the source code files (*.cpp and *.h files) for your program will be associated with this project.

The project created here and all source code added to that project will be located in a folder called "C:\tommy tiger\demo project". Your projects and code will be stored in a folder named with the project and folder names you selected. Later, when you want to copy your project (say to a removable disk) you will need to locate this file through the Windows 95 interface.

Figure B

Exploring the Workspace

The workspace window consists of a divided screen with workspace information on the left-hand panel , a blank source file panel on the right, and an output panel on the bottom (Figure A). The source panel will hold the C++ program, and the output panel will hold error messages. Change to FileView in the Workspace panel (by clicking the "FileView" tab circled in Figure A). You can then expand the file listing (by clicking on the '+'s) to view all files associated with your project.

Creating and Inserting a Source File in the Project

Figure C

Entering and Running a Program

After creating the source file demo.cpp, the workspace has an empty window in the source file panel. Type your program code into the empty window (see Figure D).

To compile and run the program (Figure D).

Figure D

The Runtime Window (program console)

The runtime environment will create a window that can accept input from the user and display output (this is the program console, corresponding to cin and cout in the C++ program). For the example program, the console will look as shown in Figure E. If your program requires keyboard input, type it in as needed. When the program completes, the line "Press any key to continue" will appear in the console window. This message indicates that the program console will wait at the end of the program until you close the console by typing any key on the keyboard.

Figure E.

If you need to get a copy of the programs input and output (say to turn in with a homework assignment) do the following:

For many assignments you will simply wish to copy the program console text into the same file as your program code. To do this, return to the developer studio window. Use the mouse to go to the place in your program text where you wish to paste the console text. Type <Ctrl>-v or use (Edit/Paste from the main menu bar) to paste the copied text. You should then enclose the pasted text in C++ multi-line comment symbols /*. . . . */ or else you will not be able to run the program again. Click the Save icon to save your work.

Saving Your Work to Floppy Disk and Deleting Your Project from the Computer

When you are done working, you will want to save your work by copying it to a removable disk. You should also delete your project from the computer's hard drive to prevent others from accessing your work once you leave the computer. Exit from the Developer Studio by clicking the X in the upper right-hand corner of the window. Us the Window interface to open your project file (following the names you used when you first create the project.

Assuming that you will be using a 3 1/4 inch floppy disk, the files left in your project folder will likely be to large to fit on your disk. Fortunately, most of these files are not needed, as they will be automatically recreated the next time you build your project. Figure F shows the files left in Tommy Tiger's project folder after the above example. The files that need to be kept are:

The rest of the files containing information generated by the compiler and linker that are need to run the program, but since these will be recreated when the program is built again later, they can be deleted. Delete these files from the folder as shown in Figure F.

Now you can copy your project folder to your removable disk. Once that is done, delete the entire folder from the hard drive.

Figure F

Returning to Work on a Previously Created Project

When you ant to return to work on a project that has already been created copy the folder that you have saved on your removable disk to the hard drive of the machine you will be working on. There are two ways to start working:

Figure G






Creating a Second Project

When you begin to work on multiple projects, you have a couple of options. You can reuse the same project and work space for all project by changing the source code files associated with the project, or you can create new projects for each job. At this point you will need to begin experimenting with the developer studio to learn various ways to manage your projects.

It is important to distinguish between a workspace/project and the Windows folder in which it is kept. It is possible to have multiple projects existing in the same folder, and it is possible to have source code files in a folder that are not part of the current project. The Windows folder simply indicates which files are physically located in that folder. The files actually associated with a project can be determined from the file view in the workspace window (as was indicated in Figure A). The files listed in the file view are the files that will be compiled and linked to attempt to create an executable program.

Here are some things you will need to learn to do to manage your projects:

Figure H

Using these three functions, you will find that you have a lot of flexibility in determining how to manage your projects. Experiment with some toy projects to get the feel for how to do this.

Notes on Managing the Source Code Editing Window

The default layout of the developer studio window does not leave much room for editing your source code. There are a number of things you can do to improve this.

First of all, you can have multiple files open in the editing window simultaneously. To do this click on the multiple files button as shown in Figure I. This will give up a view such as is shown in Figure J.

Figure I

Figure J

You can return to the single file view by selecting the button shown in Figure J.

To get more space for editing, you can hide the workspace and output windows. Do this by hitting the icons shown in Figure J. This will give you a view as is shown in Figure K.

Figure K

This will allow you plenty of room to do your editing. When you try to compile and run your program, or if you need to add or delete files from the project, use the show workspace and output windows as shown in Figure K.