Docsity

Using Microsoft Visual C++: Creating and Compiling a Console Application, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Using Microsoft Visual C++
The Microsoft Visual C++ development environment is a software application used for writing C/C++
programs. The three main areas used when writing a program are the workspace, the project and the
source file. A workspace is simply a container to easily organize projects. A project is a container to
hold any number of source files. Typically, all the source files in a project are interrelated, often to
produce a single executable program file. The hierarchy of areas, listed from highest to lowest, is the
workspace, then the project and finally the source file.
You can build many different kinds of projects with Visual C++. For our purposes only one, the
console application, is of interest. A console application (.exe) is a character-based program that does
not require screen graphics output. It looks similar to a program running on a UNIX workstation or a
terminal connected to a mainframe computer. Console projects operate in a single window, and let you
interact with your program through normal read and write commands. Console applications are better
suited to problems that require pure numerical processing rather than graphical output or a graphical
user interface. This type of application is also more portable to other platforms than other types of
applications.
Before launching the Visual C++ application, you should do two things.
(1)Be sure your Windows Explorer is configured NOT to hide known file extensions. This is
absolutely critical!!!! You should verify that this is correct EVERYTIME you sit down at a machine!
(2)Create the directory on your H: drive in which you want to work in this course. ece3331
might be a good choice. Of course, on your own PC you can use the C: drive, but this is NOT where
you should be working in a shared environment! You only have to create the directory one time, of
course.
Setting your personal preferences(inside Visual Studio)
1. Use spaces instead of tabs.
a. Choose "tools", then "options" from the menu. A dialog box should open.
b. Choose the "tabs" tab
c. For C and Fortran file types, you should use spaces instead of tabs.
d. Click OK
2. Use a fixed-width font for source windows and output windows
a. Choose "tools", then "options" from the menu. A dialog box should open (may already be open
from the previous step)
b. Choose the "format" tab.
c. Choose "Source Windows" from the "category" list box.
d. In the "font" section, choose a fixed width font such as "Courier New". You may also want to
use a fixed-width font for "Debugger Windows" as well.
e. Click OK
Creating a Workspace
1. Once the Visual C++ program has been started, choose the “New…” option from the “File”
dropdown menu at the top of the screen.
2. A new dialog box will appear. Choose the “Workspaces” tab.
update 1/26/04 1
pf3
pf4

Partial preview of the text

Download Using Microsoft Visual C++: Creating and Compiling a Console Application and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Using Microsoft Visual C++

The Microsoft Visual C++ development environment is a software application used for writing C/C++ programs. The three main areas used when writing a program are the workspace , the project and the source file. A workspace is simply a container to easily organize projects. A project is a container to hold any number of source files. Typically, all the source files in a project are interrelated, often to produce a single executable program file. The hierarchy of areas, listed from highest to lowest, is the workspace, then the project and finally the source file.

You can build many different kinds of projects with Visual C++. For our purposes only one, the console application, is of interest. A console application (.exe) is a character-based program that does not require screen graphics output. It looks similar to a program running on a UNIX workstation or a terminal connected to a mainframe computer. Console projects operate in a single window, and let you interact with your program through normal read and write commands. Console applications are better suited to problems that require pure numerical processing rather than graphical output or a graphical user interface. This type of application is also more portable to other platforms than other types of applications.

Before launching the Visual C++ application, you should do two things. (1)Be sure your Windows Explorer is configured NOT to hide known file extensions. This is absolutely critical!!!! You should verify that this is correct EVERYTIME you sit down at a machine! (2)Create the directory on your H: drive in which you want to work in this course. ece might be a good choice. Of course, on your own PC you can use the C: drive, but this is NOT where you should be working in a shared environment! You only have to create the directory one time, of course.

Setting your personal preferences(inside Visual Studio)

  1. Use spaces instead of tabs. a. Choose "tools", then "options" from the menu. A dialog box should open. b. Choose the "tabs" tab c. For C and Fortran file types, you should use spaces instead of tabs. d. Click OK
  2. Use a fixed-width font for source windows and output windows a. Choose "tools", then "options" from the menu. A dialog box should open (may already be open from the previous step) b. Choose the "format" tab. c. Choose "Source Windows" from the "category" list box. d. In the "font" section, choose a fixed width font such as "Courier New". You may also want to use a fixed-width font for "Debugger Windows" as well. e. Click OK

Creating a Workspace

  1. Once the Visual C++ program has been started, choose the “New…” option from the “File” dropdown menu at the top of the screen.
  2. A new dialog box will appear. Choose the “Workspaces” tab.
  1. Type a name for your workspace in the “Workspace Name:” edit box, for example, semxx where semxx is the current semester—this way, if you have to repeat the course (heaven forbid!) you will not get previous semester's cp1 confused with this semester's cp1.
  2. Pick a location to save using the browse button (a small button with an ellipses on it). For example, the h:\ece3331 directory. The directory must exist before you can choose it (that is why you created it above). Visual Studio will create a directory within the directory you choose, and it will be assigned a name identical to your workspace name. Click “OK” to create the workspace.
  3. You only need to create the Workspace once, assuming you want to save all of your "projects" in this same Workspace.

Creating a Project

  1. To create a project within your workspace, choose “New…” from the “File” dropdown menu. A dialog box will appear.
  2. Make sure you are on the “Project” tab. This should be the default tab when the dialog box appears.
  3. Select “Win32 Console Application” from the list.
  4. Type a name for your project in the “Project Name:” edit box, for example, cp1 might be a good choice.
  5. Be sure you have the “Add to current workspace” button selected before proceeding. This will place the new project within the workspace created earlier. Note the location path. When the next dialog appears, make sure to choose “An empty project” and click “Finish.”
  6. Click “OK” for the next dialog box.
  7. On the left side of the Visual C++ application pane, choose the “File View” tab. Notice that your newly created project is nested within the workspace. Notice that the words “ cp1 files” are in bold letters. This means that this is the current project, and any source files created will be added to this project.

Creating Source Files

  1. From the “Project” dropdown menu, choose “Add to Project” and then “New…” in the pop-out menu. A dialog box will appear.
  2. Make sure the “Files” tab is chosen. This should be the default when the dialog box opens.
  3. Choose “C++ Source File” in the list box.
  4. Type the name of your source file in the “File name:” edit box, for example “cp1.c” might be a good choice. You need to specify the “.c” extension, otherwise the program will automatically supply a “.cpp” extension. The compiler differentiates between C and C++ by the file extension, so it is important to force the compiler into treating the program as a C program with the “.c” extension. If you have not turned off the "hide known extensions" option, Windows will add the .cpp extension after the .c extension, and you wind up with a file whose real name is cp1.c.cpp. This may appear to execute properly in Windows, but when you or we transfer it to unix and try to run it in the cc compiler, it won't work!
  5. You probably do not need to choose the location to save this file. The current projects directory will be listed in the “Location:” edit box.
  6. Click “OK” and the source file will be created and opened. You can now type your source code, using the Visual C editor.
  7. Save your source file!

stopped to allow the developer to examine the process's code, variables, and register values, and, as necessary, make changes, continue execution, or terminate execution.

  1. To set a breakpoint at a source-code line, do the following:
    • In a source window, move the insertion point to the line where you want the program to break.
    • Choose the Insert/Remove Breakpoint toolbar button or press F9.
    • A red dot appears in the left margin, indicating that the breakpoint is set.
    • Note. If you want to set a breakpoint on a source statement extending across two or more lines, you must set the breakpoint on the last line of the statement.
  2. To set a breakpoint at the beginning of a function (or subroutine), do the following:
    • In the Find box on the Standard toolbar type the function (or subroutine) name.
    • Click the Insert/Remove Breakpoint toolbar button or press F9.
    • While in debug mode a red dot appears in your source code in the left margin at the beginning of the function (or subroutine), indicating that the breakpoint is set.
  3. To set a breakpoint at the return point of a function (or subroutine), do the following:
    • Start debugging, and pause the debugger in break mode (program is waiting for user input after completing a debugging command).
    • On the View menu, click Debug Windows, then click Call Stack.
    • In the Call Stack window, move the insertion point to the function (or subroutine) where you want the program to break.
    • Click the Insert/Remove Breakpoint toolbar button or press F9.
    • While in debug mode a red dot appears in the left margin of your source code, indicating that the breakpoint is set.
  4. To set a breakpoint at a label, do the following:
    • In the Find box on the Standard toolbar type the name of the label.
    • Click the Insert/Remove Breakpoint toolbar button or press F9.
    • While in debug mode a red dot appears in your source code, in the left margin at the line containing the label, indicating that the breakpoint is set.
  5. To initiate the debugger, choose “Build” from the dropdown menu, then pick “Start Debug” and then select “Go.” Pressing F5 will also start the debugger. The program will then stop at the first breakpoint it encounters.
  6. At this point, there are several options for working through the program.
    • To continue to the next breakpoint, press F5.
    • To step into the next statement, press F11.
    • To step over the next statement, press F10.
    • To step out of a loop or subprogram, press shift+F11.
    • To execute to the current cursor position, press ctrl+F10.
    • Note: all of the above commands are available on the debugging toolbar. This toolbar becomes active as soon as the debug session is initiated.
  7. It is possible, during the debug session, to view the value of most variables. This is not possible if the variable is being held in a register. To view the variables in the current subprogram, press the “Locals” tab at the bottom of the application window. To view a particular variable, the variable name can be entered on one line of the watch window, and its current value will be displayed.