Tuesday, February 2, 2016

Getting Started With VS2013 on UoM computers

On windows one of the best IDEs (Integrated Development Environment) to use on Windows is Visual Studio 2013. Visual Studio is primarily written for developers to build complex applications using graphics, audio and interactions with the user. However, during this course we are only interested in coding mathematics, so will not really touch on the many things that Visual Studio can do for you. You will need to know how to edit, compile and run simple Win32 console applications. The following ‘How To’ is for the Windows network at the University of Manchester. First click on the start menu and type “visual”, you should see Visual Studio 2013 appear to select.

You will first see a welcome screen, select the “Not now, maybe later” option.

At the next screen just select the default (general) environment and press the start button. Once the program has loaded (this may take some time), you can should now go to the menu at the top and select to open a new project. Given that each and every time you want to create a new program you will need to go through this same process, you should bookmark this page for future reference.

From the available templates on the left hand bar, select “Visual C++” and then “Empty Project” from the centre window. Change the name of the project to something that makes sense (Assignment 1, Binomial Tree, etc.) and then click ok.

You should now have a blank project. In order to write code we now need to create a new cpp file. For the most part of this course you should work on a one file one project basis, there can be only one main source file so new problems will require a new project! Go to the right hand bar and right click on the “Source Files” directory, and from the resulting menu select “Add- >New Item”:

From this screen we can now add our cpp file, rename it to whatever you like and click add.

Now we need to put some code in that file, so copy/paste the following into the file:

// include the input output stream library
// so that you can write to the screen
#include <iostream>
// use the std namespace
using namespace std;
  
// all programs must have just ONE main function
// 
int main()
{
 // output a message to the screen
 cout << " Hello world!!!!!\n";
 // finish the function by returning an integer
 return 0;
}

and then save the file.

You are now ready to compile and run your first c++ program. Go to the “DEBUG” menu at the top and select “Start without debugging”, or use the shortcut “Cntrl F5”. Click on yes to build your solution and you should see it compile and then a black window will momentarily appear and disappear again.

Obviously this is no good as you cannot see any output from the program. In order to fix this we need to go to the “PROJECT” menu and select the properties option for your project, my project is called “Project3” so I select “Project3 Properties...”.

Once the properties window is open select “Configuration Properties- >Linker- >System” in the left hand sidebar.

Now you need to change the “SubSystem” setting to get the program to stay on screen. Either by entering manually or by selecting from the drop down menu (press the small triangle on the right hand side) set this to

Console (/SUBSYSTEM:CONSOLE)

You are finally ready to go! Press “Cntrl F5” and yes to build the project and the black console will now stay on screen. You should see this:

NOTE: you will need to reset this option in the property pages every time you open a new project. After a few goes it will become like second nature

No comments:

Post a Comment