CompSci 141 / CSE 141 / Informatics 101 Spring 2013
Visual Studio 2012 Tutorial


Introduction

While this is certainly not intended to be a full-scale tutorial about Visual Studio, it should instruct you on a few of the most basic features that you'll be needing for your work in this course.


Installing Visual Studio

Visual Studio 2012 will already be installed in the ICS labs. If you'd like to use it on your own machine, you can obtain it via Microsoft's DreamSpark program (formerly called MSDNAA), to which the Bren School of ICS is a subscriber. For more information about DreamSpark, see this FAQ.

Note that most of the differences between the versions of Visual Studio (e.g., 2012 vs. 2010, 2010 vs. 2005) are not important in this course, though one nice feature of 2012 is compiler support for new features in the C++11 standard. While these features aren't critical to our work here, you still might want to install Visual Studio 2012 in this course, even if you prefer another version normally, so that you can have a fuller version of C++ to experiment with; different versions of Visual Studio can be installed alongside one another on the same machine and will co-exist peacefully.

When installing Visual Studio, you can save a good deal of hard drive space by choosing to install only Visual C++, but you can also feel free to install other parts of the package if you're interested in them. Visual C# and Visual Basic provide useful options for .NET-based Windows programming, for example, which is a handy thing to learn about.

When you first run Visual Studio, it asks you what kind of work you intend to do with it. Choose the option that says you'll be doing "Visual C++ development," which will configure the application to work best for doing C++ work. The rest of this tutorial assumes that you've made this choice. (If you didn't, that's okay, but the user interface may be laid out differently, and keyboard shortcuts may not be the same. Be warned.)


How Visual Studio organizes a program

Visual Studio can compile programs as simple as the infamous "Hello World!" program, or large-scale applications whose output includes many executables and libraries. Because it is an industrial-strength tool, Visual Studio needs to be able to manage a great deal of complexity. To that end, it organizes a program in the following way:

Creating a new solution, or a new project within a solution, can be a somewhat daunting task. Visual Studio asks you to choose from among a large variety of project types (console-mode Windows programs, Windows programs with GUIs, various kinds of libraries and shared components, etc.) and provides a wealth of configuration options. To simplify things for this course, I've organized the starting point into solutoins for you, so you shouldn't need to go through this task.

I highly recommend that you use the provided solution as a start, since we'll be grading your project by importing the code into an identically-configured solution. Creating your own solution and using the wrong settings creates the very real possibility of your program working on your machine but not on ours; if you use a different setup from ours, you bear the risk that differences will have an effect.


Okay, I have a solution... Now what?

There are a few principal tasks that you'll engage in as you write your programs. Refer to the following screenshot as I continue with the tutorial:

(Your Visual Studio window may be organized somewhat differently, as I've manipulated various settings over time to change the layout to my liking. Still, you should see the window divided into the sections you see above, even if they're arranged differently. Also, note that there has been a fair amount of controversy in the Windows development community about the colors and styles in the Visual Studio 2012 user interface; if you think this is not the prettiest window you've ever seen, I agree, though there are themes and other settings that you can tweak if you'd prefer a different look and feel.)

Along the left side of the window is the Solution Explorer, which, for our purposes, is a list of all of the source and header files in your program. The largest portion of the window is devoted to viewing and editing your code, providing a fairly straightforward and typical code editor. Along the bottom of the window is the Output area, which will show you the output generated by compiling your program or performing a search.

First and foremost, you'll need to add new source and header files to your program. Fear not; this is easy to do. Right-click on the name of your project in the Solution Explorer, select Add on the ensuing menu, then select New Item... on the next menu. You'll then be prompted with a dialog box that may overwhelm you at first. Don't let it! Select Code on the "Categories" list along the left, then select "C++ File (.cpp)" or "Header File (.h)" in the Templates section, then type a name into the Name field. It's that simple! From there, you can write code into the file, and Visual Studio will add it to the list of things to be compiled.

When you want to compile your program, go to the Build menu and select Build Solution (or press F7 as a shortcut). The output of the compilation process should appear in the Output area of the window. If there are errors, they'll be displayed to you after compilation is complete.

If your program compiles with no errors, it's time to run it. You can run it with or without debugging. To execute your program in debug mode, select Start from the Debug menu or press F5. To execute your program without debugging, select Start Without Debugging from the Debug menu or press Ctrl+F5. A word of advice: When you run your program with debugging, its console window disappears immediately after the program ends, without allowing you to view its output. When you run without debugging, a Press any key to continue prompt is displayed in the console window when your program ends. So, unless you really need the debugger, running your program without debugging will probably be easier for you to use.

At some point in your development, you may decide that you don't want a source or header file anymore. You can remove it from your solution by simply right-clicking it in the Solution Explorer, then selecting Remove on the ensuing menu. It should be noted that this doesn't remove the file from your hard drive; it only removes it from the solution. You'll probably also want to delete the file, so that you don't accidentally submit it.

Feel free to explore Visual Studio more on your own. Don't let yourself get too bogged down in its various features; for now, it's probably best to stick to the simple stuff and concentrate your energies on your C++ programs. Enjoy!