| Previous | Main | C & C++ Compilers | Next | Site Index | Download | A Complete Visual C++ Tutorial |


 

 

 

 

Using Microsoft Visual C++ .Net

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Creating Win32 Empty Console Mode Application Steps

 

It is recommended to use the compiler that is ISO/IEC C/C++ complied and install any patches or updates or Service Pack for the compiler.  The Visual C++ .Net steps to run our first Win32 console mode application quite similar to the previous version of the Visual C++ compilers.

  1. Launch the Microsoft Visual Studio .NET.  A blank IDE window as shown below should be displayed.

 

  1. This window is the Visual Studio .NET integrated development environment (IDE).  It contains all the tools you’ll need to create full-featured, easy-to-use applications.

 

Creating a Project

 

The first task is to create a new project for our testing program. To create a project, follow these steps:

  1. Under the File menu, point to New, and then click Project.  Alternatively, you can press Ctrl+Shift+N (shortcut).  The New Project dialog box will be displayed.

  2. Select Visual C++ Projects in the Project Types pane, select Win32 Console Project in the Templates pane, and then type testing in the Name text box.

 

 

  1. Choose a location for your new project in the Location combo box, either by typing a directory path in the Location combo box or by clicking Browse and navigating to the appropriate directory.

  2. Click OK to start the Win32 Application Wizard.  This project will possess a simple, text-based interface, similar to an MS-DOS screen from years ago that will be adequate for our purposes.  Before proceeding, though, you need to change one setting.

 

 

 

  1. Click the Application Settings text on the left side of the dialog box.  The right side of the dialog box changes to show the current wizard settings.

  2. Select Empty Project under Additional Options.

  3. Click Finish to create the project.  The wizard correctly initializes all the compiler settings for a console project.

 

Adding a C++ Source File to the Project

 

An empty project is not particularly exciting on its own, so let’s add a new C++ source file.  As always in Visual Studio .NET, you have many ways to do the same thing.

  1. Either right-click the testing icon in Solution Explorer, point to Add, and then clicks Add New Item, or click the Add New Item button on the toolbar ().  Either action will open the Add New Item dialog box as shown below.

 

 

 

  1. Select C++ File (.cpp) from the Templates pane on the right, type test or test.cpp in the Name text box, and then click Open.  Visual Studio .NET creates an empty source code file and adds it to the project for you.

 

Now it’s time to start typing some C++ code or just copy and paste :o) sample codes for testing.

 

Adding C++ Code to the Source File

 

Type in the source code for the program, as shown here.

 

 

Notice that the keywords automatically turn blue provided that you spell them correctly, the comments are green etc.  Actually you can change these setting.

 

Building the Executable

 

The next step is to build the executable.  The term build in Visual Studio .NET refers to compiling and linking the program. Visual Studio .NET compiles any source files that have changed since the last build and, if no compile errors were generated, performs a link.

To build the executable, select Build Solution from the Build menu or press Ctrl+Shift+B.  An Output window displaying the build progress will appear near the bottom of the Visual Studio .NET window.  If no errors are encountered, the message Build: 1 succeeded, 0 failed, 0 skipped should appear in the Output window.

If any problems occur, the Output window will contain a list of errors and warnings, as shown here.

 

 

If the error or warning is generated by the compiler and not the linker, double-click the error line in the Output window to place the cursor at the line in the source file where the compiler encountered the error.  Fix the error may be you might have misspelled a keyword or forgotten a semicolon etc, and rebuild the project.

 

Executing the Program

 

Once you’ve eliminated all errors and you’ve successfully built the project, you can finally execute the program. Choose Start Without Debugging from the Debug menu to run the program.  You can also press CTRL+F5 to execute the program.

You’ll see the output of your program, with a line at the bottom of the output telling you to “Press any key to continue”.  This line is added by the IDE so that the console window doesn’t simply disappear when the program has finished running.

 

 

Summary:

 

To

Steps

Create a new project in Visual Studio .NET.

Use the File, New, Project menu item, or press Ctrl+Shift+N.

Add a file to a project.

Use the File, New, File menu item, or press Ctrl+N.

Build a Visual Studio .NET project.

Use the Build, Build Solution menu item, or press Ctrl+Shift+B.

Execute a program from within Visual Studio .NET.

Use the Debug, Start Without Debugging menu item, or press Ctrl+F5.

 

Useful Advanced Setting

 

For advanced setting normally useful for programmer during the building process are the setting of the Programming Environment and the Project’s Property.

For Programming Environment you can click Tools Options… The following dialog box will be launched.

 

 

What settings you want to set depend on your needs.  Another useful one is the Project Property setting.  Click Project menu Properties.  The following dialog box will be launched.

 

 

The needs of these settings depend on your program you are developing.  Normally useful during the program building (Compile and Link) and debugging.

To debug your program click Debug menu Start sub menu (F5).  You also can Step Into (F11) or Step Over (F10) as shown below.

 

 

During the debugging process you can view other information by selecting Debug menu and Windows sub menu as shown below.

 

 

All the C and C++ program examples compiled at Tenouk.com is unmanaged.  The .Net used is Unmanaged (/clr is not set).  The steps to set or verify this setting is shown below.

 

Project menu your_project_name Properties… sub menu Configuration Properties folder General subfolder Used Managed Extension setting set to No.

 

 

 

---www.tenouk.com---

 

 

Further digging:

 

  1. Check the best selling C, C++ and Compilers at Amazon.com.

 

 

 

 

 

 

| Previous | Main | C & C++ Compilers | Next | Site Index | Download | A Complete Visual C++ Tutorial |