< Previous | Contents | Next >
Creating Your First C++ Program
Follow these steps to write, save, compile, and run your first program using Microsoft’s Visual Cþþ 2010 Express, a popular and free IDE for the Windows platform.
1. Download Visual Cþþ 2010 Express from http://www.microsoft.com/ express/downloads.
2. Install Visual Cþþ 2010 Express, accepting the default options.
3. Launch Visual Cþþ 2010 Express. You should see what appears in Figure A.1.
4. From the application menu, select File, New, Project. In the New Project dialog that appears, select Win32 from the Installed Templates pane and select Win32 Console Application from the pane to the right. In the Name field, type game_over. In the Location field, browse to the location to save your project by clicking the Browse button. I recommend creating a new folder for the project. (I store my project in C:\Users\Mike\Desk- top\game_over\.) Last but not least, make sure the check box is checked for Create directory for solution. Your New Project dialog should look similar to the one in Figure A.2.
Hin t
It’s generally a good idea to store each project in its own folder.
383
384 Appendix A n Creating Your First C++ Program
Figure A.1
Visual Cþþ 2010 Express on startup.
Figure A.2
The New Project dialog, filled out.
Creating Your First C++ Program 385
5. With the New Project dialog filled out, click the Okay button. This will bring up the Win32 Application Wizard—Overview. Click the Next button. This will take you to the Win32 Application Wizard—
Application Settings. Under Additional options, check the check box for Empty project. Your screen should look like Figure A.3.
Figure A.3
The Win32 Application Wizard – Application Settings, defining an empty project.
6. In the Win32 Application Wizard—Application Settings, click the Finish button. This will create and open a new solution for your project, as pictured in Figure A.4.
Hin t
If the Solution Explorer is not displayed, from the application menu, select View, Other Windows, Solution Explorer.
7. In the Solution Explorer, right-click the Source Files folder. From the menu that appears, select Add, New Item. In the Add New Item dialog that appears, select Cþþ File (.cpp). In the Name field, type game_over.cpp. Check out Figure A.5 for a completed Add New Item dialog image.
386 Appendix A n Creating Your First C++ Program
Figure A.4
Your newly created project.
Figure A.5
The Add New Item dialog, filled out.
Creating Your First C++ Program 387
8. In the Add New Item dialog, click the Add button. The empty Cþþ file named game_over.cpp appears, ready for editing. In the game_over.cpp Cþþ file, type the following:
// Game Over
// A first C++ program #include <iostream>
int main()
{
std::cout << "Game Over!" << std::endl; return 0;
}
Your screen should look like Figure A.6.
9. From the application menu, select File, Save.
Figure A.6
Your new Cþþ file, edited.
388 Appendix A n Creating Your First C++ Program
10. From the application menu, select Debug, Build Solution.
11. Press CtrlþF5 to run the project and enjoy the fruits of your labor. You should see the results shown in Figure A.7.
Figure A.7
The big payoff: seeing your program run.
Congratulations! You’ve written, saved, compiled, and run your first Cþþ program.
Hi n t
For more detailed information about Microsoft Visual Cþþ 2010 Express, please see its documentation.