Creating Visual C++ Console Applications
A console application is executed in the DOS shell console environment. This type of
application eliminates the complexity of creating the Windows event loop programs and
places direct control to the "main" function within a C or C++ program. This
type of application is greatly useful for creating simple shell tools or unit test
drivers.
Creating console applications is useful for programming programming exercises and
projects for C and C++ courses. After you master the language and building console
applications, you will want to learn
about the Windows operating system from the application level, the Windows event loop,
callback programming and Graphical User Interface, GUI application design. When you are
comfortable with these topics, then you will want to master the Microsoft Foundation
Classes and network based programming.
Procedure to creating Visual C++ Console Applications
- Start Visual C++
[Start] (button), [Programs], [Microsoft Visual C++ 6.0]
- In Visual C++
<File>, <New>, <Win32 Console Application>
- Enter the workspace information into the workspace dialog.
Location >> "c:\cpp_work or press the [...] buttons to
browse to your work directory"
Project Name: hello_world
Click [Ok]
- Select the radio button for an "Empty Project"
Click [Finish]
Click [Ok] at the information dialog.
- Visual C++ has now created a folder called hello_world in the c:\cpp_work
directory. This is where your workspace files will be stored.
Next place visual studio work space into FileView mode by selecting the [FileView] tab.
Click on the + next to the "hello_world files"
- hello_world files
|- Source Files <<< This is where your *.cpp files go!
|- Header Files <<< This is where your *.h files go!
|- Resource Files <<< Not used
- The folder called "src" is to containt the *.cpp file and the folder
called inc and enter "cpp" into the extension area. This area is where you
source code goes. Next create a folder called "inc" and enter
"h" into the extension area.
- Create the specification file for the hello_world example.
Select the "Header Files"
[File] - [New] - [C/C++ Header File]
Enter the name "hello_world"
VCPP ads the .h
- Create the implementation file for the hello_world example.
Select the "Source Files"
[File] - [New] - [C++ Source File]
Enter the name "hello_world"
VCPP ads the .cpp
- Click the [+] sign next to the folders and observe the files which have been created.
- Enter the following text into the specification hello_world.h. Do Not Cut and Past from here!
// hello_world.h
// Hello World Specification
// Class 1 COP2224
// Date: 8/25/1998
// Student: John Smith
#include <iostream>
class Hello_World
{
public:
void
Show ( void )
{
std::cout << "C++ Hello World" <<
std::endl;
}
};
// eof hello_world.h
- Repeat the previous step with the following code for the file hello_world.cpp. Do Not Cut and Past from here!
// hello_world.cpp
// Implementation for hello_world
//
// Date: 8/25/1998
// Student: John Smith
#include "hello_world.h"
int
main ( void )
{
Hello_World hw;
hw.Show();
return(0);
}
// eof hello_world.cpp
- Now save the workspace and all the files.
[File] - [Save Workspace]
- Now Build the program.
[Build] - [Build hello_world.exe]
- Expected results...
Hello World
Press any key to continue