Vous êtes sur la page 1sur 42

CS2311 - Tutorial 1

Getting Started with Visual

Studio 2012
(Visual Studio 2010 are no longer available on
MSDNAA, please choose Visual Studio 2012
which is quite similar to 2010)

Introduction and installation of Visual studio (VS)
Writing, compiling, and executing C++ programs
using VS

Working Environment
In this course, you will be working with PC
under Windows 7 or 8, and all the
programs will be written with Visual
Studio 2012.
In this tutorial, you will explore and get
familiar with the MS Visual Studio 2012
compiler working environment.
Visual Studio 2012 is an integrated
developing environment (IDE). Inside the
Visual Studio 2012 compiler, you can edit,
compile, link, run, debug and manage
your programming projects.

Setting up Visual Studio

Environment (In CSC Labs)
Locate Microsoft Visual Studio 2012 from the
WorkDesk icon on Desktop.
Visual Studio 2012 professional and Visual Studio
2012 professional ultimate are similar IDE and
both of them can be used in this course

Introduction and installation of Visual studio (VS)
Writing, compiling, and executing C programs
using VS

Steps for writing, compiling and

running c programs

Create a project and project folder

Create a folder for storing programs (source
Add the source code to project
Compile and run the program

Create the project

1. Select File
2. Mouse over New
3. Click Project

Create a C++ Console

1: Select Visual

4: type a folder name, e.g.


6: click OK

2: Select Win32 Console

3: Select the folder where you want the
project saved
e.g. c:\user\<your login
ame>\documents\Visual Studio

4: uncheck Create
directory for

Customize the project


click Application

Customize the project


1: check Empty project

2: click Finish

Add a C++ program file into the

1. Right click Source
2. Mouse over Add
3. Click New Item

Add a C++ program file into the


1: select C++ File(.cpp)

3: click Add
2: enter a file name, e.g. tut1

Writing code

The area for

typing project
The cpp file
just created

Writing code

Type the Hello World program

Build (Compile) your program


click Build Solution

Build your program

If the program can

be built successfully,
you will see 1
succeeded here

Execute your program


click Start without


Result of Execution

Try it out!

Comment this line

Rebuild the project


This time, click

Rebuild Solution
because the
project has been
built before

Got an error message

0 succeeded, 1 failed
means the program
has problem! No
executable is made

If you try to execute it


You will get an error


And will not have an

expected result

A better way: Locate the

A maker will be
placed beside the
line that makes
program failed to

Double click the

error message

Fixed the error

Add std:: before

cout, it tells the
compiler the cout
object is defined in
std namespace

Rebuild the project: Fixed!

It is success this

Copy your project out

Locate your project (the

path may be different if you
choice different path in
project creation
Copy the whole folder
into your USB or

Reload your project

Close it first!

VS without project loaded

Click File >> Open

Locate and select your


1. Select tut1.sln from

the project folder you
copy before
Click Open

Your project is loaded

Work on other program with the

same project
Within the same project, we can only have one
main function. If you want to add another
program file with function main, exclude the
existing one first!

Introduction and installation of Visual studio (VS)
Writing, compiling, and executing C programs
using VS

What you have done in this

Create a Visual Studio 2012
Create and add a C program into
the project
Write a simple Hello World
Build and Execute the program
Locate the syntax error of a

Downloading a Visual C++ 2012

compilers (try it yourself at home)
Visual Studio 2012 can be found at:

Login using your student ID as login name

and password.
Click "MSDNAA Software Center"
Select Visual Studio 2012 Professional Edition
Add the following items to the shopping cart

Visual Studio 2010 Professional Edition DVD

Download and run the executable files.

Burn the iso files to DVDs (or using software
to mount the DVD image).
Click setup to install.

You have to .Trust us

Click this

Enter your CS lab account

(Check the email sent by CS Lab

Enter the MSDNAA Software


Click this

Select Visual Studio 2012

1. Select Developer Tools

Select Visual Studio

Download the Ultimate


Select Visual Studio

2012 Ultimate

Add VS2012 to shopping cart

Click Add to Cart and then