Beruflich Dokumente
Kultur Dokumente
This appendix contains the instructions for using Microsoft Visual C++ 2010, which is a full-featured
Integrated Development Environment (IDE) for the C++ language. Visual C++ 2010 is available as a
stand-alone product, called Visual C++ 2010 Express Edition, or as part of Visual Studio 2010. At the
time of this writing, you can download a free copy of Visual C++ 2010 Express Edition at
www.microsoft.com/express/Downloads/#2010-Visual-CPP.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
2
screen might look slightly different than the one shown in Figure D-1.) When you start the Express
Edition of Visual C++ 2010, on the other hand, your screen will appear similar to Figure D-2.
Important note: To select a different window layout, click Tools on the menu bar, click Import and
Export Settings, select the Reset all settings radio button and then click the Next button. Select the
appropriate radio button in the Save Current Settings pane, click the Next button, click the preferred
collection of settings (such as Visual C++ Development Settings), and then click the Finish button.
Click the Close button.
Toolbox
window
be sure these
check boxes
are selected
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
3
Toolbox
window
be sure these
check boxes are
selected
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
4
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
5
4. If necessary, close the following windows by clicking their tabs and then clicking the Close button
on their title bars: Class View, Property Manager, Team Explorer, Code Definition, Output, and
Database Explorer.
5. If the Solution Explorer window is not open in the IDE, click View on the menu bar and then click
Solution Explorer.
6. Click the Auto Hide (vertical pushpin) button on the Solution Explorer window’s title bar to auto-
hide the window.
7. Place your mouse pointer on the Solution Explorer tab and then click the Auto Hide (horizontal
pushpin) button on the window’s title bar to permanently display the window.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
6
Although you can create many different types of C++ applications, the applications you will create in this
book are C++ console applications. A console application is a program that runs in a Command Prompt
window.
Figure D-5 Completed New Project dialog box in Visual Studio 2010
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
7
Figure D-6 Completed New Project dialog box in Visual C++ 2010 Express
5. Click the OK button to close the New Project dialog box. The Win32 Application Wizard dialog box
appears and displays the Welcome to the Win32 Application Wizard pane. Click the Next button to
display the Application Settings pane. Verify that the Console application radio button is selected.
Select the Empty project check box. See Figure D-7.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
8
6. Click the Finish button. The computer creates a solution and adds a Visual C++ project to the
solution. It also records the names of the solution and project, as well as other information pertaining
to the project, in the Solution Explorer window. See Figure D-8.
Figure D-8 Solution and project names shown in the Solution Explorer window
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
9
select this
template
Figure D-9 Completed Add New Item dialog box in Visual Studio 2010
2. Click the Add button to close the Add New Item dialog box. The computer adds an empty C++
source file to the project. It also records the file’s name (MyFirstSourceFile.cpp) in the Solution
Explorer window. See Figure D-10.
source filename
insertion point
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
10
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
11
asterisk
3. Save the program. You can do so by clicking File on the menu bar and then clicking Save All. Or,
you can click the Save All button on the standard toolbar.
Important note: If you prefer to use the buttons on the standard toolbar, it’s best to use the Save All
button and not the Save button. This is because the Save button saves only the changes made to the item
selected in the Solution Explorer window. For example, when the source filename is selected, the Save
button saves only the changes made to the source file. Similarly, when the project name is selected, only
changes made to the files included in the project are saved. The tooltip box that appears when you rest
your mouse pointer on the Save button indicates the files that will be saved. In this case, the tooltip box
will say “Save MyFirstSourceFile.cpp” when the source file’s name is selected in the Solution Explorer
window, “Save MyFirst Project” when the project’s name is selected, and “Save MyFirst Solution.sln”
when the solution’s name is selected.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
12
3. Click Debug on the menu bar and then click Start Without Debugging. The program’s output
appears in a Command Prompt window, as shown in Figure D-13.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
13
Important note: Be sure to use the Start Without Debugging option rather than the Start
Debugging option. If you use the Start Debugging option, the editor will not automatically display the
“Press any key to continue” message in the Command Prompt window. Instead, the window will close
immediately after the program output is displayed. If you want to use the Start Debugging option,
you will need to enter the system(“pause”); statement above the return 0; statement in the program.
4. You can change the color of the Command Prompt window’s background and text to make the
display clearer. Right-click the Command Prompt window’s title bar and then click
Properties. Click the Colors tab. Select the Screen Text radio button and then click the black
square. Click the Screen Background radio button and then click either the light gray square
or the white square.
5. You also can change the font used to display the text in the Command Prompt window. Click the
Font tab. Click Lucida Console in the list of fonts and then select the Bold fonts check box. Click
20 in the Size list box and then click the OK button. See Figure D-14.
Figure D-14 Result of changing some of the Command Prompt window’s properties
6. Press Enter (or any key) to close the Command Prompt window.
7. Close the Output window by clicking the Close button on its title bar.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
14
3. Click the OK button to close the Options dialog box. See Figure D-16.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
15
To introduce two syntax errors in the current program and then debug the program:
1. Change cout in Line 8 to cut. Also delete the semicolon that appears at the end of Line 9. See Figure
D-17.
first error
second error
2. Save the program. Click Build on the menu bar and then click Build Solution. The Error List
window indicates that the program contains 4 errors. Double-click the first error message in the
Error List window. See Figure D-18.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
16
arrow
Error
List
window
3. The editor displays an arrow at the location where the error was encountered in the program. In this
case, the arrow is pointing to the statement on Line 8. The error message indicates that the word
“cut” is undeclared. This simply means that the compiler does not recognize the word. Change cut in
Line 8 to cout.
4. Save and then build the program. The Error List window indicates that the program now contains 2
errors. Double-click the first error message in the Error List window. See Figure D-19.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
17
5. The error message indicates that a semicolon is missing before the word “return”. Although the error
message and arrow refer to Line 10, it’s the instruction in Line 9 that caused the error. Recall that you
deleted the semicolon at the end of that line. Type ; (a semicolon) at the end of Line 9.
6. Save and then build the program. The Output window indicates that the build was successful.
7. Finally, click Debug on the menu bar and then click Start Without Debugging to run the
program. Press any key to close the Command Prompt window.
8. Close the Output and Error List windows.
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)
18
Appendix D – 5/25/2010
An Introduction to Programming with C++, Sixth Edition (0538466529)