Welcome to C++ Done Right! Follow this tutorial with a little patience and you’ll be a happy confident C++ programmer in no time at all. It is a complete work in progress and is rather unstable if you will. Some sections are kinda short, others don’t exist yet. Lessons are prone to constant updates, and may have small typos and errors.
Who’s this tutorial for?
This tutorial is generally aimed at:
- Programmers from a language other than C++ that already know some programming concepts but want to learn C++
- People that have never programmed before, and want to get started with C++
- C++ programmers that want to refresh their memories, or need an explanatory reference
What’s covered in this tutorial?
The C++ language of course! To be more specific, we’ll be looking at:
- Variables
- Mathematics
- Functions
- Conditional Statements
- Loops
- Arrays
- Pointers
- References
- Classes
- Vectors
- Templates
These are concepts we look at, but some concepts have been broken into multiple lessons as to not overwhelm anybody.
Understanding Compilation and Interpretation
Before we start building our first program, we need to understand two terms. The first is compile, and the second isinterpret.
Compiling is when a program is translated from a high level easy to understand source code, to assembly and later binary code. It is then saved in an executable format and can be used when ever you need. Make sense? The first part of the tutorial explains it quite well:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/tools-compiling.html
Interpreting code is in a sense the same as compiling, but the code isn’t saved in a executable file. Instead, every time you use the code,
it is translated.
If you ever hear about JIT compilation, understand this is a mixture of both compiling and interpreting.
Generally compiled programs are faster, but interpreted programs can be executed sooner.
Compiling in C++
To compile, you’ll need a compiler, and in this tutorial we’ll be using the Visual C++ (VC++) compiler from Microsoft. A free version is available from:
http://www.microsoft.com/express/vc/
Now, since most of the people taking this tutorial are new to programming, we’ll be using an Integrated Development Environment(IDE). An IDE is an application that tries to put development tool and editing tools all in one place. It usually works with the compiler and debugger and comes with tons of stuff for your advantage.
Visual C++ is both a compiler and IDE, so install it.
Compiling Your First Program
Here, we are gonna compile a program. I won’t explain it, we’ll be doing that in the next lesson. Generally when programming you’re gonna wanna make a Project. A project is a way for the IDE to group all your different files in a single directory, and know where to out put the executable.
Open VC++, anf goto ‘File’ > ‘New’ > ‘Project’. Choose ‘Win32 Application’, and make it an ‘Empty’ project. Now from the ‘Projects’ menu, select ‘Add New Item’. Make a new .CPP file and add the following code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Press F7 to compile, or F5 to run in the debugger. If all went well you compiled your first program in C++!
Conclusion
In this lesson we installed a compiler and IDE as well as compiles a program. Next time we’ll take our real first steps into the language by deciphering the little snippet you just put together.