| Previous | Main | C & C++ Compilers | Next | Site Index | Download |


 

 

Using Microsoft Visual C++ 5.0/6.0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.  Compilers also have bugs????

 

 

1.         Launch the Microsoft Visual C++ from the Start Programs… or from wherever the shortcut is.

 

2.         From the Visual C++ IDE, select File menu then New sub menu.  The following dialog box appears.

 

Microsoft Visual C++ compiler new project

  1. Then in the Projects pane, select the Win32 Console Application.  In Project name, type your project name (for example, testing in this case).  Select the Create new workspace radio button.  Check the Win32 check box for the Platforms:.  Then click the OK button.

 

Microsoft Visual C++ compiler new project name and location

 

 

  1. The following dialog box appears.  Select An empty project radio button.  Then click Finish button.

Microsoft Visual C++ compiler new project of console mode application

   
  1. The following summary dialog box appears.  Just click the OK button.

Microsoft Visual C++ compiler new project summary

   
  1. Next we are going to add item in our project.  Select Project menu then Add To Project sub menu then New... sub menu. The following dialog box appears.

Microsoft Visual C++ compiler new project add source file

   
  1. In building real applications there are a lot of resources involved as can be seen on the left pane.  For Tenouk.com Tutorial we only need a single source file.  Select the C++ Source File.  In the File name: type the source file name (for example, testing).  The file extension will be added automatically and it is .cpp.  Make sure the Add to project: tick box is ticked.  For the Location, up to you where to put the file by clicking the , to browse your desired path.  It should be in the same path as your project.  Then click the OK button.

Microsoft Visual C++ compiler new project add source file and location

   
  1. Next, type or copy source code example and paste into the editor for the source file on the right window, the editor.

Microsoft Visual C++ compiler new project add source codes

   
  1. Next we are ready to build (compile and link). Select Build menu Build filename.exe or press F7 or click the icon.  Any error or warning will be displayed in the output window at the bottom.  Before you can execute there must be no error.

Microsoft Visual C++ compiler new project build-compile and link our first program

   
  1. Finally executing our first program.  Select the Build menu then, Execute filename.exe menu or press Ctrl+F5 or click icon.

  2. If there is no error, the following console should be output.  If there are errors, you have to correct the errors before re building and re executing the program.  Any errors and/or warning will be displayed in the output window at the bottom.  By double clicking the error or warning, the error or warning location in the source codes will be highlighted.

Microsoft Visual C++ compiler new project console mode output example

   

Creating a Windows executable file

 

All program examples in tenouk.com are built in Debug mode.  To create a Release Mode version we have to change the Visual C++ project to a Release Mode.  After rebuilding the program, the executable should be portable on Windows machine.  To run the program at the command prompt from any relative path you can include the executable under the %root%\system32 directory.

Let take another simple program example (this is for win32 console mode application).  We write, compile and link the following program as mentioned in the previous steps.

 

/* C - Program to display square and square root for a given number */

/* for sqrt() function */

#include <math.h>

#include <stdio.h>

 

int main( )

{

       /* variable named x and floating-point data type */

       float  x;

 

       /* standard output */

       printf("\nEnter one positive number (1, 2, 3. . .): ");

       /* standard input */

       scanf("%f", &x);

 

       printf("\nx = %f ", x);

       printf("\nSquare for x is = %f", x * x);

       /* sqrt() is the predefined function, defined in math.h */

       printf("\nSquare root for x is = %f\n", sqrt(x));

       return 0;

}

 

Output:

 

Enter one positive number (1, 2, 3. . .): 2.5

 

x = 2.500000

Square for x is = 6.250000

Square root for x is = 1.581139

Press any key to continue

 

   

From the Debug Mode we change it to the Release Mode.  The steps:

 

Click the Build menu Set Active Configuration… sub menu.

Microsoft Visual C++ compiler new project generating portable executable release version

   

From the following box, select the win32prog – Win32 Release (win32prog should be your project name).  Then click OK button.

Microsoft Visual C++ compiler new project set the release version configuration

   

If there any other settings that you want to change such as optimization etc., change it through the project Setting menu as shown below.

Microsoft Visual C++ compiler new project change other release setting if any

   

Microsoft Visual C++ compiler new project more release settings

   

Then rebuild (compile and link) your program.  Make sure there is no error.  The executable should be a Release version.  Finally you can copy the executable manually from your project folder.  An example is shown below.

Microsoft Visual C++ compiler new project portable executable PE is ready!

   

Then, to run the program at any relative path of the command prompt, for Win 2000 server, we put it under the C:\WINNT\system32\ directory.  An example of running our previous program at any relative path of the command prompt, after the executable was copied to C:\WINNT\system32\ folder is shown below.

Microsoft Visual C++ compiler new project running the portable executable anytime anywhere in the Windows machines

 

 

---www.tenouk.com---

 

 

 

 

Further digging:

 

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

  2. Visual C++/CLI programming.

  3. The .NET network programming.

 

 

 

 

 

 

| Previous | Main | C & C++ Compilers | Next | Site Index | Download |