Computer Science
Department
Framingham State
College
Spring 2003 D. Keil
Using Microsoft Visual C++ at Framingham State College
1. What computer labs can I use?
You may use your laptop, any other PC, or any lab, including the Computer Science lab, located in Hemenway Hall, Room G18, for use of Computer Science students exclusively. Every PC there and elsewhere on campus, including CASA, should have a C++ compiler installed. See user policies posted in the labs you use.
2. How do I log in?
Students registered for C/C++ courses automatically have accounts on the network. Your account name is the string “frc” followed by your student ID. When you log in, you will have access to your own account space on the server, which is accessible whenever you log in anywhere on the network. At the end of your session at the computer, be sure to log out (Start / Shut down).
3. To enter the development environment
Microsoft Visual C++ is a Windows application that supports development of C and C++ programs. These instructions assume that you have some knowledge of how to use Windows. The C++ compiler is part of an integrated development environment (IDE). It contains an editor, compiler, linker, loader, debugger, and other tools to allow you to create programs in source-code form (a C or C++ file) and to convert them to executable form and test them.
To enter the IDE, go to Start / Program / Computer Science / Microsoft Visual Studio. The IDE’s online documentation will be displayed. Double-click on an item in the tree-structured table of contents on the left (e.g., Visual C++ Books / Tutorials / Introduction / About This Book, or Visual C++ Books / C/C++ / C++ Language Reference / Lexical Conventions / C++ Keywords) to see text on the right. Click on the text and press the Page Down key to scroll through it.
4. Overview of compiling, building, and executing a program
You use an editor to create or to modify a C or C++ program source file, which is a text file with a .c or .cpp extension to its name. You may compile, build, or execute your C or C++ source file. The compiler translates your source code into linkable machine code. The linker builds an executable machine-code file from the linkable object code. The loader loads the executable file into memory and runs it as a console application, with a black background.
5. To compile, link, and run an existing source file
1. Compile and build from your network account area; if you try to compile a file on a floppy disk, you will run out of disk space and an error message will display. From the menu at the top of the screen, select File (Alt-F – press the F key while holding down the Alt key), followed by Open, and in the directory dialog box find the file you want to test. The example files for one instructor’s section of CS I, for instance, are in Z: \ Software \ dkeil \ 63152. You should see program source code fill the editor window. If you lose the text from view, select Window from the menu and look at the bottom of the pulldown menu for your .c or .cpp file.
2. To compile: from the Build menu select Compile. You may see a dialog, “This build command requires an active workspace…” Answer Yes. (You must reserve a “workspace” for each source file you want to test. The name of the open workspace must match the name of your source file.) You will see “Compiling” in the status window at the bottom of the screen. If the program compiles correctly, you will see the name of your source file with the extension .obj and the message, “0 errors 0 warnings” in the status window. (Or: to compile and link in one step, skip step 2 and go on to step 3.)
3. To link your application: from the Build menu, select Build. The status window will show “Linking…” and the name of your source file with an .exe extension. (Or: to link and execute a compiled program in one step, skip step 3 and go on to step 4.)
4. To execute your program: from the Build menu, select Execute. Your application will run in a Windows DOS or Console window (black background) as a separate task that will appear on your task bar.
5. You may save your program as edited, under a new, different name from the original one. To do so, select File / Save As and follow instructions under step 2 of section 6.
6. When you finish testing a program, use the choices on the File menu to close both your source file and its workspace.
6. To create and run a new C or C++ file
1. If you have been compiling other programs during the current user session, choose File / Close workspace. (Otherwise any build you do will compile the source file referenced by the current workspace, not the one you want to compile.)
2. Create a new file: From the File menu, select New, then select Text file in the dialog. An empty editor window will appear. Type your source code and edit it if necessary. You may widen the text pane of the split screen by dragging the border to the left.
3. Save your file to your network account area or on your floppy disk: From the File menu, select Save. You will see a dialog box for saving files. Save your file to your user account area. If you are writing in the C language, use the extension .c. for your source file name; if C++, use the extension .cpp.
4. Compile, link, and execute your program, following steps 2 through 6 of section 5.
7. If there are errors in your program
If the compiler detects syntax errors in your source code, it will create a window labeled Output with error messages. Double-click in one of these message lines to return to your source code and correct the error. Notice the error description at the bottom of the IDE window as you edit your file.
Many error messages are misleading. Try to understand the error by looking at the line of code where it occurs and referring to your programming-language knowledge. For help with the C or C++ language, highlight a word or operator in your program and press the F1 key.
One error may trigger many error messages. We suggest you correct one at a time, recompiling each time. When you have corrected an error, recompile and test your program.
8. To print your program and test output
To
print source file:
With your source code window selected (at the front), select File / Print. The printer at the front left corner of the lab will shortly print the file.
To print test output:
Copy text from the DOS output window (black background) and paste it into the editor. To copy, you have a choice of two methods.
(a) With your executable program’s window selected, press Alt-Enter to put the application screen
in DOS text mode. The screen will be black with white text and no windows. Copy
the output to the Windows clipboard by pressing the Print Screen key on the top row of keys. Or:
(b) Click on the dotted-line rectangle in the upper part of the output window; drag the mouse across the text to be printed so that it is highlighted; click the second icon (“Copy”).
To paste text into the editor:
1. Return to the MSVC IDE. Open a new window in the editor by pressing File / New, or scroll to the end of your source file.
2. Paste the output into the editor (Edit / Paste).
3. Print the output (File / Print).
9. Intermediate files
The compiler creates many large files while building your application. Any files in your own C++ source subdirectories with extensions .ncb, .opt, .plg, or .dsp may be safely deleted.
10. For assistance with C or C++
If selecting Help (F1) and checking your textbook fail, talk to a tutor, to your instructor, or to another student.