Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up...

8
Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is an environment which allows you to create, edit, save, debug, compile, and run C++ programs. Projects Every C++ program is contained in its own project directory. Whenever you start a new homework assignment or any C++ program, you must create a project within Visual Studio first and add C++ source code files (text files with extension .cpp) to that project. In this handout, we will show you how. Solutions A solution is a file that groups related C++ projects together in order to organize them. You will only need to create two solutions for this course: one for your homework projects and another for example projects given to you in PIC 10A. To create your first project and solution for your homework, follow these steps: Step 1: Open Microsoft Visual Studio by clicking the purple infinity icon Uncheck the checkbox. Select “Visual C++ Development Settings.” Then press “Start Visual Studio.”

Transcript of Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up...

Page 1: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Getting Started With Microsoft Visual Studio 2012

Microsoft Visual Studio is an environment which allows you to create, edit, save, debug, compile, and run C++ programs.

Projects

Every C++ program is contained in its own project directory. Whenever you start a new homework assignment or any C++ program, you must create a project within Visual Studio first and add C++ source code files (text files with extension .cpp) to that project. In this handout, we will show you how.

Solutions

A solution is a file that groups related C++ projects together in order to organize them. You will only need to create two solutions for this course: one for your homework projects and another for example projects given to you in PIC 10A.

To create your first project and solution for your homework, follow these steps:

Step 1: Open Microsoft Visual Studio by clicking the purple infinity icon

Uncheck the checkbox. Select “Visual C++ Development Settings.” Then press “Start Visual Studio.”

Page 2: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Step 2: Select “File,” then “New,” then “Project.”

Step 3: Under the “Installed” and “Templates” headings, click “Visual C++” and then “Win32 Console Application” in the middle frame. Type in the name of your project “Hw1” in the text field labeled “Name” and enter the name of your solution “Homework” in the text field labeled “Solution name.” Be sure to create the project on your personal “Z:” network drive by entering the location “Z:\Visual Studio Projects\” in the text field labeled “Location.” Then click “Ok.”

Page 3: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Step 4: The dialog below will appear. Click “Application Settings” and then select “Console Application,” uncheck “Precompiled Header” and “SDL checks,” and then check “Empty Project.” Click the “Finish” button.

Step 5: Your solution “Homework” and Project “Hw1” are displayed in the Solution Explorer. Right-click “Source files,” select “Add”, then “New Item” to create source code.

Page 4: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Step 6: Under Visual C++, select “Code.” Then select “C++” File in the middle frame. Enter the name of your C++ source code file “HelloWorld.cpp” and press “Add.” This will create the source code file (a plain text file) inside your Hw1 Project folder and integrate it into your program.

Step 7: Type your C++ code into the source editor and press CTRL-S to save.

Page 5: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Step 8: After editing the source code file, select the “Build” menu and then “Build Hw1” to compile your project. The compiler will translate your source code into a binary executable (.exe) file written in your machine’s native language. The file “Hw1.exe” will be created as a result.

You will see the message “Build: 1 Succeeded” in the output window.

Page 6: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

Step 9: To run program, select the Debug menu, followed by ”Start without debugging.”

Step 10: The output console will pop up and display the message “Hello World!”.

Congratulations! You just completed your first C++ program!

Page 7: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

You can find the solution (.sln) file in the solution directory

“Z:\Visual Studio Projects\Homework\”

You can find the source code HelloWorld.cpp in your Hw1 project subdirectory:

Page 8: Getting Started With Microsoft Visual Studio 2012ldnguyen/pic10A/Spring'17/1_How to set up firs… · Getting Started With Microsoft Visual Studio 2012 Microsoft Visual Studio is

The object (.obj file) is located in your Project “Hw1” subfolder called “Debug.”

The standalone executable (.exe) file of your program is located in the “Debug” subfolder of your “Homework” solution folder.