C++ Tutorial for noobs - Part 1: Installation
...Back to Part 0: Introduction
Before we can use C++, we will have to install it somehow. This tutorial explains how to install Microsoft's Visual Studio 2008 under Windows and how to create a new C++ project. If you are using a Mac, you may try XCode. If you work on linux, try Eclipse CDT.
We will use the Visual Studio 2008 Express version.
If the link doesn't work anymore, just Google for "Visual Studio 2008 Express Download". Newer versions might work too, however older versions would require a lot of complicated setup so 2008 is the way to go.
Once installed, we open Visual Studio and select File->New->Project from the top menu:
Now we select Win32 as Project type and then Win32 Console Application as Template. The last step is to enter a project name and the location where it should be saved:
After pressing OK a new window appears where we press Finish. Our project was now created and we see the following source code:
// test.cpp : Defines the entry point for the console application.
int _tmain(int argc, _TCHAR* argv)
A short explanation about what the program does so far:
- The first two lines that start with // are comments, which aren't really part of the program - they are just for us humans to make notes and stuff. We can delete them if we want to.
- The #include part includes the stdafx file which (for some reason that no one understands) is just default in any new project. Whatever, let's not worry about it. If you don't have anything with 'stdafx' in there then don't worry about it either.
- The _tmain thing is the main function, also called program entry point. It looks weird with those argc and argv things, but they are default in any new project and we won't worry about them either. All we have to know is that whatever is in the _tmain function will happen as soon as we run the program - in this case, it's the 'return 0' part.
We can run it by pressing the green button at the top:
If Visual Studio says that the 'project is out of date' and asks if we want to build it, we select 'Yes' and 'Do not show this dialog again'.
Visual Studio then compiles our project and runs it, which results in the black console window showing up and then closing itself immediately afterwards - which is normal because our program doesn't really do anything yet.
On a side note: it's recommended to click on View -> Other Windows -> Error List once so if we get any errors, we can also see what and where they are. Which is... pretty useful.
Continue to Part 2: Output...