This material is not complete in any way. Its purpose is twofold: first, to enable someone who is encountering Visual C++ for the first time, but who knows some C++, to get started quickly writing C++ programs within the Visual Studio .NET programming environment; second, to convey some possibly lesser-known but quite useful features of the Visual Studio .NET IDE in the context of making life easier for the Visual C++ programmer. Suggestions for additional material to be included on this page are welcome.

Overview

The first thing to note is that if you are familiar with Visual C++ from having used Visual C++ 6.0 or an earlier version you must be prepared to climb back on the learning curve, since many features you are familiar with have changed. The Visual Studio .NET IDE is an attempt to standardize the programming environment for all programmers that Microsoft intends to support, and since previous versions of the Visual C++ IDE were the most different from the Microsoft IDE norm, C++ programmers are the ones that will need to spend the most time getting used to the new environment.

The Visual Studio .NET C++ IDE (Integrated Development Environment) allows you to write many different kinds of software, from simple console programs to DLLs (Dynamic Link Libraries) and Active Template Library Components. (No need to worry if you don't even know what the latter two are.) A console program is one that has a simple (old-fashioned, if you like) text-based interface, in which program output appears on lines that scroll upward to the top of, and eventually off, the screen.

Whenever you do something in the Visual Studio .NET version of Visual C++, you generally do it within the notion of a solution and a project. A solution in Visual Studio .NET is analogous to a workspace under Visual C++ 6.0, if you remember what that was. Like a workspace, a solution may contain more than one project. Whatever projects you've been working on are noted by Visual Studio, and you are presented with a list of the most recent ones on the Start Page whenever you fire up Visual Studio.

Visual Studio does its best to help you out when you're working. Sometimes this can be pleasant and useful. Other times it can be downright unpleasant and frustrating. It can also be quite overwhelming, when you find, for example, that quite a number of files you know nothing about have been created for you. Ignoring these extra files is usually the best thing to do.

So, it is important to have a good sense of the big picture, and not to be overwhelmed or intimidated by all the minutiae that need not concern you, at least not for the forseeable future.

Getting Started: Creating, Building, and Running a New "Win32 Console Application"

Here, in very brief form, is the sequence of steps necessary to start a new project, enter a single source code file, and then build and run the executable:

  1. Start Visual Studio from the appropriate submenu of your Start menu. After a short wait, among the things you will see on your screen will be a "Start Page" containing a "New Project" button.
  2. Click the "New Project" button.
  3. In the window that opens up, choose "Visual C++ Projects" under "Project Types:" and "Win32 Project" under "Templates:". Then enter the name of your project in the "Name:" box. The "Location:" box should contain the path you want, so just leave it, although it may be changed if you really need to make a change for some reason. (You may want to make a note of this location so that you can look there after the next step to see what files are present.) Make sure the "Close Solution" radio button is active and then click "OK".
  4. A "Win32 Application Wizard" window opens up. Click on "Application Settings" in the left pane of this window. Then choose "Console application", make sure the "Empty project" box is checked, and click the "Finish" button. (Now is a good time to go to Windows Explorer and check to see what has shown up in the location identified in the "Location:" box in the previous step.)
  5. At this point the Start Page may reappear, but you should also see a smaller "Solution Explorer" window, probably at the upper right of your screen. This window should now contain, among other things, an icon labeled by the name of your project. If so, your project has been set up but doesn't contain any source code yet.
  6. Under the "Project" menu choose "Add new item..." (or press Ctrl+Shift+A). In the window that opens up, the left pane should show "Visual C++" already highlighted, so click on "C++ file (.cpp)" in the right pane and in the "Name:" box enter a name for your file. If this is to be the file which contains the main function for your project, you may want to give it the same name as the project, but this is by no means necessary.
  7. Now click the "Open" button and an editing window will open, into which you may enter the source code for your program. If this is your first time through, try the code for "Hello, world!".
  8. When you are ready to try a build, go to the "Build" menu and choose "Build Solution" (or press Ctrl+Shift+B, or click on the "Build icon" of the "Build toolbar" if that toolbar is displayed). Your source code file is automatically saved to disk before the build. The "Output Window" will open and display the results of your build, including any compile-time or other errors that have shown up in the attempt to build your solution. Note that if you have made an error and have to make source code changes, the changes you made are again automatically saved to disk when you choose to rebuild. You can double click on any error line to show where that error has occurred in your source code, or press F1 when the line is highlighted in the "Output Window" to get more information from the Help system on the error reported in that line.
  9. If the build is successful, go to the Debug menu and choose "Start without debugging" (or press Ctrl+F5) to run your program. A console window should open and your program should run in it. The IDE supplies its own pause at the end of your program, but it is generally a "best practice" to place a pause of your own at the end of each of your programs. If you don't, and you run that executable by double clicking on it in Windows, you may not see all of the output from your program, since the console window that Windows Explorer opens will disappear the moment your program ends.
  10. Once you have finished to this point, you may create another project, or shut down Visual Studio.

Once you have an executable, you can run the program independently of Visual C++ in the following two ways:

Working with Files in a Project

Once you have added to your project all the files the project needs, you may perform any of the following actions.
  1. Double click on the name of a source code file in the "Solution Explorer" window to display it in the text editor window.
  2. Place the cursor in the word "include" (of any #include line), right click, and then choose "Open Document" to view that particular header file in the text editor window. Notice how a "name tab" appears for each "window" that opens up in the text editor, above the text of the currently active window. Just clicking on any such tab will make the corresponding window active.
  3. Press Ctrl+F5 at any time to run the current executable. If it has not yet been built, or if changes have been made in the source code, you will be prompted to (re)build before running. Note again that files are saved to disk as part of the build process.
  4. Choose "Rebuild Solution" from the Build menu at any time if you wish to re-build everything for any reason (whether it has changed or not).
  5. Press Ctrl+F7 if you just want to compile, and not build an executable.
  6. A potentially confusing situation occurs if your program itself reads from a data file: In this case, the IDE expects that file to be in your project directory, even though the executable is in a subdirectory called Debug in your project directory. Such a data file does not have to be added to the project, so long as it is present and in the right location. On the other hand, if you are running your program from Windows Explorer, or from the command prompt in a console window, your program and the data file from which it reads must be in the same directory, unless you supply to your program the full path to a file in some other location.
  7. Click on any file in the "Solution Explorer" window and press the Delete key to delete that file from the current project (though not from its physical location on disk).

The Text Editor: Creating and Modifying Source Code Files

The first thing to know about the Visual Studio text editor is that many of the "usual" commands for navigation and applying changes to text that are familiar to users of other Microsoft products (such as Word) also work here, and (mercifully) in the same way. Hence, assuming this familiarity, we shall not give the details of those commands here. It is therefore assumed that you are familiar with what the following keyboard commands do for you when editing text: the four arrow keys, Home, End, Ctrl+Home, Ctrl+End, PageUp, PageDown (and using the Shift key with any of these motion commands to select text), as well as Ctrl+C, Ctrl+X, Ctrl+V, Ctrl+A, and Ins.

We list below some commands and features that are either not present in other applications, or are not as widely known or used, but which you may find useful in the Visual Studio .NET Visual C++ environment:

  1. Let the editor's "smart autoindent" feature work for you. It knows, for the most part, how your code should be formatted, and you should let it decide, for example, things like what the indent level should be (4 spaces), and the proper placement of braces. This feature should be on by default. In fact, you can select a section of code that has had its formatting "messed up", or is not formatted quite right, and have the whole thing properly formatted for you automatically by pressing Ctrl+K, Ctrl+F.
  2. If a group of contiguous lines of code need to be indented or unindented one or more levels, select those lines of code and then press the TAB key to indent them an additional level, or the Shift+TAB combination to "unindent" them one level.
  3. It is a good idea to have no TAB characters in your file. You can remove all TAB characters from a file at any time by selecting your entire file with Ctrl+A and then choosing Edit | Advanced | Untabify Selection. Ideally, your default should be to have spaces inserted into your file when you press the TAB key.
  4. Ctrl+R, Ctrl+W toggles the display of whitespace in your source code. Blank spaces show up as a dot, while each Tab character shows up as two greater than signs (>>). This is a great help when to want to check whether in fact you have removed all the tabs from your source code, or any other document.
  5. Double-clicking on the little rectangular box above the up-arrow at the top of the scroll-box region at the right of the text editor window will split the current window into two equal parts horizontally, as will choosing "Split" from the "Window" menu. This gives you two views of the same file, which can be scrolled and edited independently. Double-clicking on the separating bar will return you to a single window, as will choosing "Remove Split" from the "Window" menu.
  6. Ctrl+K, Ctrl+K toggles an unnamed bookmark at the cursor line, and Ctrl+K, Ctrl+N moves to the next bookmark, while Ctrl+K, Ctrl+P moves to the previous bookmark. Ctrl+K, Ctrl+L clears all bookmarks in the current window.
  7. Ctrl+G allows you to go to various locations, including (probably most usefully) a particular line number.
  8. When the cursor is on either side of a bracket (round, square, curly, or angle), Ctrl+] will place the cursor on the matching bracket symbol.
  9. Ctrl+U/Ctrl+Shift+U converts selected text to lower/upper case.
  10. To change the font size, choose Tools | Options | Environment | Fonts and Colors, and then choose your desired size in the Size: box.
  11. To expand a source file window to full screen, choose View | Full Screen. Press Esc to return to the current window at the previous size. You can also use Shift+Alt+Enter to toggle to and from full screen mode. You can use other commands and/or menus while in full screen mode if you know their keyboard equivalents.
  12. Ctrl+Z undoes the previous change. Pressing it again undoes the change before that, and so on. If you undo one change to many, you can "re-do" the last undo with a Ctrl+Y.
  13. Clicking in the blank area to the left of the edit window selects the line opposite.
  14. Tab/Shift+Tab indent/unindent selected text one level of indentation.
  15. Ctrl+Tab cycles through the queue of open windows, much like Alt+Tab does in Windows itself.
  16. Ctrl+F opens a Find dialog box for entry of a search string, after which F3/Shift+F3 find the next/previous instances. Esc gets you out of Find and back to the source code window.
  17. Ctrl+F3 will start a search for selected text.
  18. Ctrl+H starts a Find/Replace.
  19. Ctrl+I starts and "incremental search", i.e., a search that starts as soon as you begin typing and looks for the first instance of as much as you have typed in so far, and Ctrl+Shift+I starts a similar backwards search.
  20. Ctrl+Shift+T interchanges the current and following words, while Alt+Shift+T interchanges the current and following lines.
  21. Ctrl+Delete deletes to the beginning of the next word, Ctrl+Backspace to the beginning of the previous word.
  22. Ctrl+L deletes the current line and places it on the clipboard, Ctrl+Shift+L deletes it without placing on the clipboard (i.e., its gone).
  23. Ctrl with the arrow keys provides some useful commands: Ctrl+RightArrow moves the cursor to the beginning of the next word, while Ctrl+LeftArrow moves the cursor to the beginning of the previous word. Ctrl+UpArrow scrolls the window down one line, while Ctrl+DownArrow scrolls the window up one line.
  24. Ctrl+K, Ctrl+C will "comment out" any lines you have selected, while Ctrl+K, Ctrl+U will remove the comments from selected lines commented out with C++ style comments.
  25. Visual Studio has a number of other useful features that we will not describe in detail here. We do mention them, however, since you should at least know about them, and do your best to explore their possibilities, as needed, in the course of your program development:

Debugging

As your programs get more complex, you may from time to time want (or need) to use the Visual C++ debugger to help you track down a run-time error or see where your program is going astray as it executes. When you start debugging, a number of windows will open automatically. It may be useful to explore the various options that are available to you for viewing, and for other actions, via these windows. Here is a brief list of some debugger commands:

  1. Choose your break points, which can be toggled on and off, either by pressing F9, or by clicking in the grey vertical bar to the left of the code, when the cursor is on the code line at which you wish to break during a run.
  2. Start debugging by choosing Build | Start Debugging | Go, or by simply pressing F5, or by clicking the icon on the Build mini-toolbar that shows some lines of code with a down-arrow to the right.
  3. Press F10 to step through your code (without going into functions, which may be what you need most of the time), or F11 to step through your code, including the internal code of functions.
  4. To skip over some code place the cursor at the point to which you would like to go without stopping and then press Ctrl+F10 to "run to the cursor".
  5. Press Shift+F5 to stop debugging and Ctrl+Shift+F5 to restart.

Useful Miscellaneous Information

  1. An editor macro is like a C++ function (or C++ macro, for that matter) that can be called upon to perform a specific task. A number of editor macros may be available for your use, and, if so, they will be described elsewhere.
  2. If you have used Visual C++ 6.0, you will find that the C++ in Visual Studio .NET is much more fussy about the type conversions it allows you to make. In particular, many implicit conversions that Visual C++ 6.0 happily permitted are now flagged as warnings by Visual C++ .NET, a change you might find frustrating at first but which you should realize is a change for the better.
  3. If your program uses command-line parameters and you are testing it with the IDE, in the "Solution Explorer" window select your project, right click and choose "Properties". In the "Property Pages" window that opens, choose Configuration Properties | Debugging and then enter your command line arguments in the "Command Arguments:" box.
  4. If your program uses RTTI (which stands for Run-Time Type Identification, or Run-Time Type Information, depending on where you read about it), this feature must be "turned on". To do this, first right click on the name of your project in the "Solution Explorer" window and then choose "Properties". In the "Property Pages" window which appears, choose "C/C++" and then "Language". One of the lines in the sub-window that then appears is labeled "Run-Time Type Info", and this option must be set to Yes.
  5. When you start using C++ with Visual Studio .NET, you may get some (or a lot) of "Warning" messages at compile time that you are not used to seeing, particularly if you are using the STL. These warnings will be numbered, and if you know that whatever the "problem" is truly will not affect your code, you can avoid such a message with a line like the following placed at the beginning of your program, just before your #include directives. If the warning is numbered 4786 (for example), put in this line:
    #pragma warning(disable:4786)
    A "pragma directive" such as this one is a compiler-specific instruction of some kind meant for the C++ pre-processor.
  6. If you upgrade your compiler at any point, it is a good idea to delete any .pdb and .pch files associated with each of your projects, to avoid build errors with the upgraded compiler.

Files Used/Created by Visual C++

If you are curious about what's in the many different kinds of files that Visual C++ produces in the course of its meanderings toward your final executable, check under "Files Created for Visual C++ Projects" in the MSDN Library.