Creating a new Visual Studio.NET C++ project
The Microsoft C++ compiler, like most integrated
development environments, combines source files into a project. A "project"
is a group of files that contain related source code; in addition, a project may
contain other resources, such as icons, menus and widgets.
Usually, a project will compile to create an executable files, a .exe
file; however, other kinds of projects can create libraries (lib or
dll files) that are subsequently used when linking or executing a
program.
Visual Studio.NET combines multiple projects into a single
"solution", which is encapsulated in a .sln file. For CSE 167, we
use only the simplest possible solutions, namely, our solutions contain only a
single project.
When you are writing a new program, you will want to create new project and solution to hold the program. This can be done by following the following procedures. (Warning: the procedures change somewhat with every new release .NET.)
Step 1: Have the Visual Studio.NET C++ compiler running and as the
active window. If you have a solution or project currently open, close it from the
the File menu.
Then under the
File menu, choose New -> Project... . A dialog box
opens. Choose the Project Type of Visual C++ Projects. Select
Win32 Console Project (sometimes also called a Win32 Console Application,
but not just "Console Application")
as the project type in the Template window.
Then choose a project name (something informative, but not too long), and a
directory for a location (the C++ compiler will automatically create a folder
whose name is the same as the project). Verify that the location is ok,
then click OK.
A WIN32 Application Wizard window appears. Click on
Application Settings on the left, then click the check box for Empty
Project. (The Console Application box should remain
checked.) Then click Finish.
Step 2: You may start by creating new .c,
.cpp, and .h files in the usual way (use
New from the File menu). Once a source
file is created, you must add it to the project. You do this by first
saving the file with a name that ends in .c or .cpp or
.h (for C source, C++ source or header file), and right-clicking
in the source file window and selecting Add to Project and
the Project name
Alternately, look under the Project menu
for other ways to include a file in the project.
If you do not include the .cpp file in the project, the
compiler will not compile it.
Step 2': Instead of creating a completely new source file,
you may wish modify an existing source file for your new project. (For
instance, another OpenGL program, that you want to modify). To do this,
first create a copy of the source file and put it in your new project
directory. Then open the file, and use the procedure as
above to add it to the project. Don't forget to use the same procedure for header
files.
If you skip the step of making a new copy of the
file before adding it to your project, then you will have the same source file
in two different projects. If you modify the file for one project, it
will also change the other project and in most cases, this is not what you
want!
Use the method of Steps 2 and 2' to add additional source files to your workspace as needed. The C++ compiler has a "Solution Explorer" window on the left side of the screen. This gives convenient access to the different files in your project.
Step 3: Compile and run your program in the usual way.
Using I/O (stdin/stdout): If you run your program it will open a text window (in addition to any OpenGL window). The standard C I/O routines, such as printf, may be used to read and write from the window, via stdin and stdout. If you want to do this, don't forget to include the necessary C header file with #include <stdio.h>.