Visual C .Net Compiler
Visual C .Net Compiler
NET TUTORIAL
INTRODUCTION
Microsoft Visual C++ .NET allows you to create many different types of applications.This guide addresses creating and using Console Applications. A console application is a program that runs inside a DOS window.This guide is divided into the following sections:
Starting Visual C++ .NET Creating and Executing a Single-File Console Application Importing and Executing C++ Source Code Files
Figure 1-1
Microsoft Visual C++ .NET Tutorial Figure 1-1 shows the initial application window. If your application window looks different, you may need to adjust the settings.You can change the settings by clicking the Start Page tab and selecting the My Profile option.There you can set various default settings. First, select Visual C++ Developer in the top drop-down box under the heading Profile. Also, set Show Help to External Help, as shown in Figure 1-2. A dialog box will pop up with a warning that the change to External Help will not take place until Visual Studio is restarted. Click the OK button and continue. Figure 1-3 shows how the profile looks after making these selections.
Figure 1-2
Figure 1-3
CREATING
AND
EXECUTING
One of the most common programs encountered in an introductory C++ programming class is a single source code file that contains the main function. To construct this type of application, you need to:
Create a Win32 Console Application Project Add a source code file Write the program Execute the program Debug the program
Figure 1-4
When the New Project dialog box opens, click on Visual C++ Projects in the Projects Types pane, then on Win32 Console Project in the Templates pane. Enter the following information (see Figure 1-5):
Enter the project name in the Name textbox Select the location for the project in the Location textbox
The application provides a default location for saving projects or you can select your own location by pressing the button to the right of the location textbox to open the Choose Directory dialog box. Press the OK button after entering the required information into the dialog box.When the Win32 Application Wizard appears, click on Application Settings, select Console application from the Application types and check Empty project (see Figure 1-6) and then press the Finish button. The Solution Explorer now contains the information about your project (see Figure 1-7.)
Select project
Figure 1-5
Figure 1-6
Figure 1-7
Figure 1-8
When the New File dialog box appears, select Visual C++ in the Categories pane and C++ File (.cpp) in the Templates pane. Click the Open button (see Figure 1-9).
Figure 1-9
To save the file with a specific name, on the File menu select Save Source1 As.When the Save File As dialog box appears (see Figure 1-10), select the folder to hold the file (it generally should be the same as the project name) from the Save in dropdown window, then type in a name (the .cpp extension will be added automatically.) Press the Save button to complete the action.
Figure 1-10
Figure 1-12
10
Figure 1-13
Compiling a program
Figure 1-14
11
After the build process has successfully completed, you can now execute the program by selecting Start Without Debugging from the Debug menu. (See Figure 1-15)
Figure 1-15
The program results will appear in a new DOS window. Notice that the phrase Press any key to continue has been added to the program output. This additional code was added to keep the DOS window open until you have had a chance to view the output and press a key on the keyboard. (See Figure 1-16.) Once a key on the keyboard is pressed, the program stops execution and the DOS window closes. This output phrase is not actually included in your program, as you would see if you opened a DOS window and executed the program directly.
12
Figure 1-16
Program results
13
Figure 1-17
Compile error
Error pointer
Figure 1-18
Locating error
14
IMPORTING
AND
Often you will want to compile, build, and execute programs that you did not write, or that you wrote and stored in other locations. Consider, for example, the case where you want to execute a source file provided as part of a textbooks supplemental information. The steps are nearly identical to those described above. First you need to construct a Project file as described above. Next, instead of adding a new source file using the New command as describe above, you import the existing file into the project.This is accomplished by selecting the Add Existing Item option located under the Project menu. (See Figure 1-19.)
Figure 1-19
Once the file is part of the project (it will be listed in the Source Files folder in the Solution Explorer pane) you can double-click its name to display it in the editor pane. Then you can compile, build, and execute the program as described above.
Summary
15
SUMMARY
Microsoft Visual C++ .NET allows you to create many different types of applications. This guide addressed creating and using single source file Console Applications, but the basic operations are the same for more complex programs.
Always start by creating a project file of the appropriate type Create blank files for writing your own programs or import existing files into the project Compile Build Execute Debug, if necessary