c & c++ - Visual Studio

Contact
PC-compilers
last-news
PIC-microcontroller
AVR-microcontroller
Supports
weakly newsletter
c++
=> Visual Studio
=> C++ Language
=> arrays
=> Functions
=> Windows Programming
=> Using AppWizard
=> MFC Model
Counter
DS1821Thermostat Programmer
pic-asm-foundations
free links downloads
free downloads
mikroc library
PWM software
Home



 

Visual Studio

For C++ we will use the Microsoft Visual Studio IDE.   The IDE is the same one you saw in the Java segment of the course.  There, our use of the IDE environment was only for convenience.  Here we will try to include it in a significant way.
    Initially we will developing what is called a Console application.  These applications will be run from the  MSDOS window - same way we ran the Java programs.  Our default input (cin) and default output (cout)  and default error (cerr) is the MSDOS window.  Typically  there are three broad stages to get a program to run

    Create the source code (VS Editor)
    Compile and link the code (  Build Command)
    Run the source code (Run Command)

We should be doing all our work within the VS editor/debugger environment.  The environment provides a broad set of development tools for completing, testing and refining your program. For example, the development environment includes a text editor, resource editors, build options, an optimizing compiler, an incremental linker, a source code browse window.  Apart from the initial layout that appears when starting the Visual Studio,  the environment provides

    An Integrated Debugger
    Integrated Resource editors for windows.  They allow you to design and create bitmaps, cursors,icons,menus,dialogs
    Spy++:  a graphical view of the system's processes, threads etc
    MFC (Microsoft Foundation Classes) Tracer :  a debugging tool for MFC classes
    Control Wizard : used for Custom controls using the MFC library
    Test Container: for testing Custom Controls
    Process Viewer:  for setting and tracking Current process and threads
    WinDiff:  allows comparison of two files or directories

Type of Files

When we ran Java through the VS environment we were primarily interested in the *.java  and the  *.class files.  In executing a project in VS several additional files are created.  Even if we are not dealing with most of them  the file extensions define the type of information they contain( from Documentation):

PRJNAME.DSW :This is the workspace file used within the development environment. It organizes all the projects into a single workspace.

PRJNAME.OPT: This is the workspace options file used within the development environment. It stores all the user options you create for your workspace, so that each time you open the project workspace it has the look and feel you want and includes any customizations you have made.

PRJNAME.DSP: This is the project file used within the development environment. In previous versions of Visual C++ this file extension was .MAK. It stores the information specific to your project. There will be a separate .DSP file for each project you create. .DSP files are not compatible with NMAKE. You must export a makefile to build with NMAKE.

PRJNAME.CLW :This file is used by ClassWizard to store information about the classes in your project

PRJNAME.ODL: This file contains the Object Description Language source code for a control type library. This file is used by Visual C++ to generate a type library. The generated library exposes the control's interface to other Automation clients.

PRJNAME.NCB: This is the No compile Browser file. It contains information generated by the parser which is used by ClassView, WizardBar, and Component Gallery. If the file is accidentally or deliberately deleted, it is automatically regenerated.

README.TXT: A file (located in the parent directory of the project) that describes each file in your project using the actual filenames created by AppWizard or ControlWizard.

PRJNAME.H This is the main include file for the program or DLL. It contains all global symbols and #include directives for other header files. It derives the CPrjnameApp class from CWinApp and declares an InitInstance member function. For a control, the CPrjnameApp class is derived from COleControlModule.

PRJNAME.CPP This file is the main program source file. It creates one object of the class CPrjnameApp (which is derived from CWinApp) and overrides the InitInstance member function.

PROJNAME.RC, RESOURCE.H This is the resource file for the project and its header file. The resource file contains the default menu definition and accelerator and string tables for a generic MFC application. It also specifies a default About box and an icon file (RES\PROJNAME.ICO). The resource file includes the file AFXRES.RC for standard Microsoft Foundation class resources. If toolbar support has been specified as an option, it also specifies the toolbar bitmap file (RES\TOOLBAR.BMP).

There are are lot more files - depending on the type of project.

The IDE

We have seen the IDE before.  It is the same one we encountered in Java.  Start Visual C++ 5 from the start menu.  A quick tour:

The initial screen:

To review,  the Top region is the Menu and Toolbar area.  The Left region is the Project resource area.  The Center region is the text editor and debugger area.  The Bottom window provides the results from the compilation and linking process.  Double clicking on the error statement will point to the line in the source code.  We will attempt to use these features as we write code for C++.

The First Program

    Start VC++
    From the File menu Choose New

Depending on what is installed in the Visual studio on your machine you will see a list of Project Types like :

Select the Win32 Console application as indicated above

Alternately you can start with a new file and select a C++ File as shown below

 

      Type in the following code
 

 /*
// our first program in C++
*/
 

# include <iostream.h> // include the library for
                      // handling input and output
 
 

int main() // main method NOTE : returns an integer
{
 cout << "hello World !" << endl;

 // cout  : write to the screen/console -
 //          same as debug.print; System.out.println

 //  <<   : exteraction operator

 //  endl  : linefeed

 return(0);  // finished execution
}
 

Typical C++ Program

typical C++ program  has four parts:

1.    C++ relies on external standard libraries to provide Input and Output operation.  The information the program needs is available in  the library file  iostream.h

2.    C++ programs usually have preprocessor directives such as the include directive.  The directives start with # character

3.    Additional  functions()  if necessary.

4.    The main()  function is used as a starting point for execution.  The main() function conventionally returns the integer value of  0  to indicate successful execution.
 

In our first program, note there are no user defined ClassesThe program executed in the MSDOS environment. (a console)

Today, there have been 11 visitors (19 hits) on this page!
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free