Tutorial 1

Okay, lets start from the very beginning. Open up visual studio and Click “File -> New -> Project”. As we’ll be developing C++ apps on the Windows PC platform you’ll want to choose “Visual C++ -> Win32” from the project types and then select “Win32 Console Application” from the templates. This just means that we’ll be working on an application that runs in a console window. Now name your project (I’m going with “Tutorial 1” for simplicity) and click “OK”.

Now the project wizard will pop up. Click next then tick the “Empty project” box (we don’t need the wizard to do anything clever for us). Then click finish.

You should now see “Tutorial 1” listed as a project in the Solution Explorer. Within this solution there are 3 directories. We want to get coding so right click on the “Source Files” directory and select “Add -> New Item”. Under the “Code” category select the C++ file and give the file a name (I’m going to go with Main.cpp as this will be our main code file). Then click “Add”.

Now you’ve got your empty file lets start adding some code!

Enter the following into your file

int main() 
{ 
    return 0; 
}

This is pretty much as basic as a program can be, if you run it you’ll notice that it does nothing! Let’s go through what we’ve typed in:

int main() 

This is the programs “entry point”. All programs of this kind have to have an entry point as it is where the program starts. In C++ programs (and quite a few other languages) this is called the main function. The word int means that this function returns an integer which indicates whether the function completed successfully or not.
That is exactly what the following line does:

return 0; 

This ends the main function by returning 0. In C/C++ convention a return code of 0 means that the function was successful, anything else indicates a failure.

Next>>

  1. No comments yet.
  1. No trackbacks yet.

Tell me what you think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: