1.Introduction to Visual Studio and C++
The purpose of this tutorial is to introduce the basics of working in the Microsoft Visual Studio 2010 software development environment. Microsoft Visual Studio (VS) consists of a collection of tools that allow a programmer to edit, compile, debug, test and deploy applications on a variety of operating systems such as Microsoft Windows and Windows Mobile devices. Such tools are often called an Integrated Development Environment (IDE). Other popular IDEs include Eclipse (www.eclipse.org) and Xcode (developer.apple.com/xcode).
Microsoft offers a number of different versions and levels of VS products that vary in their features. For a comparison, please visit the Microsoft VS web site: http://www.microsoft.com/visualstudio/en-us
Visual Studio 2010 provides tools for writing and compiling programs written in Visual Basic, C++, C#, and F#. This tutorial will focus on using VS for C++ development.
There are a number of ways to develop C++ programs including:
- Windows 32 bit Console application (Win32 Console).
- Windows Application using Microsoft Foundation Classes (MFC).
- Windows Application using Windows Forms tools.
- Windows Application using Windows Presentation Framework (WPF).
This tutorial focuses on writing Win32 Console applications using the C++ language using the 2010 version of Visual Studio Ultimate.
2. Obtaining Microsoft Visual Studio
Many colleges and universities subscribe to the Microsoft Developers Network Academic Alliance (MSDN AA) also known as “DreamSpark” that provides free or reduced cost copies of Microsoft development tools for student use. For example, at Baruch College: http://www.baruch.cuny.edu/bctc/student/index.htm). The IEEE Computer Society also provides access to MSDN AA for student members (http://www.computer.org/portal/web/membership/benefit-microsoftsoftware).
Microsoft also provides free “Express” editions of specific IDE’s and compilers for individual languages. For example, the Visual C++ 2010 Express edition can be downloaded for free and can be used to carry out the activities in this tutorial. It is also suitable for most programming courses. The current web site for Visual C++ Express is: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
One other issue that may face some students is the fact that Visual Studio only runs under the Windows operating system (such as Windows XP, Vista or Windows 7). If you have a MacBook, iMac or other Apple system running MacOS that uses an Intel CPU, there are a few possible alternatives you can try. Many modern Apple computers that use Intel CPU can run the Windows operating system. Note that you will need a legally licensed copy of Windows operating system to do this. There are two main ways to accomplish this:
- You can set up your Mac to “Dual Boot” both OS X and Windows. One product that can enable this is Apple BootCamp software.
- You can run Windows OS “side by side” with Mac OS X using a “virtual” computer such as VirtualBox
3. Visual Studio Solutions and Projects
Visual Studio organizes all of the files, references, data connections and other elements into a hierarchy with the following headings:
Solution: A solution contains all of the projects required to meet a particular business goal. For example, an “accounting solution” may contain projects for general ledger, accounts receivable, and accounts payable.
Project: The set of specific items such as source code files, icons, images, scripts, database connections and other items required to create a project. For example, a project to create one software program might contain a few source code files that are compiled together.
For most beginners and for small applications, a single solution containing a single project will be sufficient. This is the case used throughout this tutorial as well.
4. The Code, Compile, Debug Cycle
Visual Studio has a number of different features that assist the software developer in carrying out these tasks. As source code is typed, VS can often detect basic syntax errors by underlining suspicious code in red. This draws the developer’s attention to those parts so corrections can be made. The “Intellisense” feature can also suggest appropriate methods or functions that might apply to a given object or variable. The compiler prints a list of any errors or warning it may find in the source code and provides links to the parts of the source code that require attention. Various debugging features allow the developer to pause the program and inspect variables and other parts of the program to ensure they are operating correctly. This “Breakpoint” feature is demonstrated later on in the tutorial.