Structured Programming
An Introduction to Visual Studio and C++
0.1 Introduction
This is a short session to familiarize working with the Visual studio programming and development
environment. You can use Visual Studio to create many kinds of applications, from simple store apps
and games for mobile clients, to large, complex systems that power enterprises and data centers.
You can create:
1. Apps and games that run not only on Windows, but also Android and iOS.
2. Websites and web services based on ASP.NET, JQuery, and AngularJS.
3. Applications for platforms and devices as diverse as Azure, Office, Hololens, and Kinect.
4. Games and graphics-intensive applications for a variety of Windows devices, including Xbox.
Visual Studio by default provides the support for C#, C and C++, JavaScript, F#, and Visual Basic. Here
we are going to work with C++.
0.2 Preliminaries
Make sure you have access to your home directory. Visual Studio should create a place for all of your
workspaces in c:\documents\visual studio\Projects. Check that in this case.
You can find out which edition of Visual Studio is right for you at Visual Studio Editions.
You can install Visual Studio 2015 by downloading it from Visual Studio Downloads. If you need to know more
about the installation process, see Installing Visual Studio 2015.
Note that any version you download from the Visual Studio website might be slightly different to the versions
that we are running on the department machines, but all of the concepts should be the same.
On the department machines, Visual Studio can be found through the following menus:
Start Button-All Apps Visual Studio
This program works similar to any other software product, i.e. you open up the program, and you then either
create a new program or load an existing program.
When you have finished, you exit Visual Studio by selecting File-Exit.
When you create an application in Visual Studio, you first create a project.
2. In the Visual C++ category, choose the Win32 Console Application template, then name the project
and Press Ok.
3. When the Win32 Application Wizard appears, choose the Finish button.
The components of the Visual Studio IDE that we will be working with are as follows:
a) Code Editor Window for editing source code manually.
b) Error List Window for displaying information about a specific error message.
1. In the code editor window enter a blank line before the line return 0.
2. Enter the following code cout << "Welcome to Lab 0\n";
A red squiggly line appears under cout. An error message appears if you point to it.
This error message cout is included in the <iostream> header file also appears in the Error List
window. You can display the window by going to the menu bar, choosing View, then Error List.
#include <iostream>
3. To include the iostream header, enter the following code after this header
using namespace std;
#include "stdafx.h".
You probably noticed that a box appeared as you entered code, providing suggestions for the characters
that you entered. This box is part of C++ IntelliSense, which provides coding prompts, including listing
class or interface members and parameter information. You can also use code snippets, which are pre-
defined blocks of code. For more information, see Using IntelliSense and Code Snippets.
Note that: The red squiggly line under cout disappears when you fix the error.
You can debug your application now to see whether the sentence Welcome to Lab 0 appears in console window.
Start the debugger by choosing Debug from menu bar, and Start without Debugging
stdafx.h describes both standard system and project specific include files that are used frequently
but hardly ever change.
iostream provides basic C++ standard library input and output services.
using namespace std is used to replace std:: in each sentence Without using namespace std;
when you write for example cout <<; you'd have to put std::cout <<;.
Program Statements, Every program statement must end with a semi-colon ";".
main is a section where any code within it will be executed when we run our program. The Code needs to be
placed within the braces that follow the definition of main as below:
0.5 Exercises
The following is a short list of tasks aimed at demonstrating some of the features of Visual Studio and C++.