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 http://blogs.msdn.com/silverlightgames.
I won’t use a video this time, although I am tempted to.
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.
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:
It would appear the next dialog box is a useless, but if you click application settings you will also see the following:
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)
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.
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.
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.
What you console app might look like:
So what is <iostream>? Why the two colons ::, return 0 and so forth.
It's nice small tweak for the "Start without Debugging" behaviour... Many a time I have to add equivalent of Console.ReadKey() to the end of console application to see it freeze and let me have the chance to check the output.
I'm interested that whether the line "Press any key to continue" is added by complier option, or just by running "the application" and "PAUSE" command sequentially...
Hey Cheong00,
Good to hear from you. I am back and the C++ story is going to be awesome.
Also check out touchdevelop.com :)
Using VS2012 ExpDesktop, I like not having to include "system("pause");" before my "return 0;" to see the output. Starts to compensate for the SCREAMING!!! menu headings.
Looking forward to more from you, Surf4Fun.
I am using Visual Studio 2012 and I have followed all your instructions here but why am I getting this error:
1>------ Build started: Project: ConsoleApplication2, Configuration: Debug Win32 ------
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help me! Thanks in advance. c:
Hmm, had a question...
Is there a difference between visual studio express and regular? Im kinda confused about #include "stdafx.h"
It is similar to this other one I found earlier draalin.com/writing-your-first-c-program
Is that include actually required??
Hey SheWilliam,
Sorry about the delay. You would get the fail if your code isn't correct for some reason, there should be an error message above it.
Hello James B.,
There are a lot of differences between Express and Regular or professional, the main one is in testing and using addons, as well a bunch of other stuff like the debugging capabilities. If you are not a student and strapped for cash, then Express is likely the best thing for you. If you have the cash to buy Regular or Professional then do so. If you are a student then get Visual Studio Ultimate from your school's MSDNAA or Dreamspark administrator.
Legal Note:
Restrictions: