|
December 2003 Technical Tip – Microsoft Visual C++ .NET
Quickstart
I recently had the opportunity to teach C++ using Microsoft Visual C++
.NET. This was my first experience with the .NET platform so I had some
apprehensions. I will admit there were a few bumps, but once I determined
how to get started it was smooth sailing. I took careful notes of the
process as I thought some readers might benefit from my experience. So
here's the simple way to use Microsoft Visual C++ .NET.
Determine where you want to keep your files
- Begin by determining where you want to keep your files. For example,
I created a folder C:\Bill and will refer to it as such in the
instructions which follow.
Creating a Visual C++ .NET Project
- If you have another project open already choose File, Close Solution
- Create a project as follows:
- Choose File, New, Project
- Visual C++ Projects, Empty Project (.NET)
- Name: XyzProject
- Location: C:\Bill
- OK
- Important! Choose View, Solution Explorer
- Create a main( ) method as follows:
- Within Solution Explorer, right click on Source Files
- Choose Add, Add New Item
- Templates: C++ File (.cpp)
- Name: main
- Location defaults to C:\Bill\XyzProject
- Open (can add the code now or later)
- This creates main.cpp. Of course, main.cpp could have another
name...
- ...but within a Project, only one file can contain a main( )
method.
- Create a header file (interface file, or .h file) as follows:
- Within Solution Explorer, right click on Header Files
- Choose Add, Add New Item
- Templates: Header File (.h)
- Name: XyzClass (for example)
- Location defaults to C:\Bill\XyzProject
- Open (can add the code now or later)
- This creates XyzClass.h
- Create a class file (implementation file, or .cpp file) as follows:
- Within Solution Explorer...right click on Source Files
- Choose Add, Add New Item
- Templates: C++ File (.cpp)
- Name: XyzClass (for example)
- Location defaults to C:\Bill\XyzProject
- Open (can add the code now or later)
- This creates XyzClass.cpp
To see line numbers while editing
- Choose Tools, Options, Text Editor, C/C++, General, Line Numbers, OK
- This will make it easier to find offending statements in the event
of compile time errors.
To compile a single unit
- To compile a single unit, such as to compile XyzClass.cpp after
creating XyzClass.cpp and XyzClass.h, choose Build, Compile (or press
Ctrl+F7)
To build the project
- To build the project (compile all units within the project
and create a .exe file) choose Build, Rebuild XyzProject
If you get error message C1010
- If you get the following message: "main.cpp(24) : fatal error
C1010: unexpected end of file while looking for precompiled header
directive"...it's probably because you are set to use precompiled
headers.
- Turn off precompiled headers as follows:
- Choose View, Solution Explorer
- Within Solution Explorer, right click on the project (XyzProject
above)
- Choose Properties, C/C++, Precompiled Headers
- Click in the box to right of "Create/Use Precompiled Headers"
- Choose "Not Using Precompiled Headers"
- Apply, OK
To execute your project
- Choose Debug, Start Without Debugging (or press Ctrl+F5)
Go to the articles index. Written
by Bill Qualls. Copyright © 2003 by Caliber Data Training
800.938.1222 |