Writing your first C++ Program using Visual Studio 2012

In previous blogs I have shown you how to set up Visual Studio 2012 so that it will function on Windows 8, 7, and so forth using the Azure VM, although we haven’t created a program to upload to the store.  That will be covered in another parallel blog series over at https://blogs.msdn.com/silverlightgames.

I won’t use a video this time, although I am tempted to. Smile

Open Visual Studio 2012 using the Windows 8 Client or the Azure VM (if you are using a Windows 7 or Apple computer), we are going to start with the usual boring Console Window.  Sorry.  Visual Studio 2012 differs from VS 2010 as it will create a default name.

image

Since you won’t be living with this app just keep the default name.  Not a good practice, but hey, let’s keep it really easy:

image

It would appear the next dialog box is a useless, but if you click application settings you will also see the following:

image

 

Select Empty Project and then Finish.  If your IDE looks like the following, that would be pretty boring, so add the solution explorer by clicking on View-Solution Explorer or use ctrl+alt+L (good idea to memorize the keystrokes while you are a student)

image

After the solution explorer shows up, you have an empty project, which means it doesn’t have anything in it.  You will need to add a simple couple of lines of code.

image

Select the C++ File (.cpp), give it a name or not.  This is just boring console app that you will forget about in a few minutes after reading this blog.

image

 

Add code that looks like the following to your new Source File, the file with the extension of *.cpp:

#include <iostream>

int main()
{
    std::cout<< "Hello world and all that" << std::endl;
    return 0;
}

If you run your program using F5 then the console will pop up and then close.  To see your beautiful code press CTRL+F5, when you do this then the console app will wait for you to press the enter key to continue, which means it will close.

 

Pretty simple.  And useless, except that it is your first program in C++.  Not something you can show Mom, or maybe you can show it to your Mom, she will smile and think you are pretty smart.  But not anyone else will be overly impressed.  Except for you.  You should be.  Now you can say you have written some C++ Code.  Good work.

 

image

What you console app might look like:

image

So what is <iostream>?  Why the two colons ::, return 0 and so forth.