CPP
From Global Programming Syntax
C++ Ahh... Tutorial. By EvilDavo
I'll teach
1. C++ language basics as simple as I can put them.
2. Further explanation for people like me who want to know why stuff is the way it is.
3. Code examples of how the stuff could be used.
4. And some programming concepts, Eg. Multi-Source-File Programming and Object Orientated Programming (OO).
I'm going to assume you've got a good development program (IDE).
Eg. Visual C++ Express Edition.
Ok, we'll begin.
Lesson 1 - Hello World!
Example
#include <iostream>
using namespace std;
int main ()
{
cout << "hello world!";
system ("PAUSE"); // don't get too familiar with this. You probably won't use it in a serious project.
return 0; // success!
}
Basics
This is known as a preprocessor directive as it starts with a '#':
#include <includes a header>
IO stream is the standard C++ library, which we're "including" with our program, so we can use the function cout.
Preprocessor directives (start with a '#') work differently to the rest of the code.
using namespace std; Means that from this point on we don't have to write std::cout, just cout.
int main () This is the main function. The entire program starts at the '{' and ends at the '}' (or a return). Note that these are curly brackets.
cout is a function which prints the string (words within the "") to the console window. This tutorial only covers the basics in a console window style. Usually a function will take the form, function (some_value); but this function is "different". You will learn to make your own "different" functions later. Suffice it to say, cout << "hello world!"; is basically, cout ("hello world");
Note: After every C++ statement or declaration, you must include a ';'. Forget this and cause yourself great pain. It'll become clear with experience.
return ends the function (and the program in this case), reporting a success (0).
Compile it and it should print out something like the following
Output
hello world
Press any key to continue...
More
Preprocessor Directives are done to the code before the code is compiled.
They don't follow the rules of C++ or the structure of the code. They are
actually quite simple, so although they don't follow the rules of C++,
don't think you'll have to learn this great big difficult new language as
well as C++.
What's with the '<<' in cout you might ask. It's so that you can do this:
cout << "I am " << someNumberValue << "years old";
For doing actual graphics (eg. for making games), search for a Game Engine. There are several
good free ones available that use C++.
For doing basic windows-style stuff you may want to learn the basics of the Windows API. I'm sure there are frameworks / engines available that make this easier though.
Conclusion
Boring, right? I hope not ):
You need to know this stuff before you can properly use an engine to do cool stuff though.
I promise to try to make it fun though (:
To the next lesson. Yay.
