page 1 page 2
page 3 page 4 page 5 page 6 page 7 page 8
here's a quick little tutorial on c++, my favorite programming language. it's the best
one there is in my opinion, and my opinion is law.
let's start off with a simple program:
code:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
return 0;
}
this is the introductory program to any language, it simply prints "hello world" on the
screen and exits. not too exciting, but you can find out some key things by looking at it.
let's take a look.
#include <iostream>
this includes the iostream header file (c++ dropped the .h extension that c has) so
the program is able to use input/output functions. hence, iostream.
using namespace std;
the using keyword, ironically enough, means you're gonna use a namespace or a piece of
it. in this case we're including the whole std (standard, mind you) namespace in our program.
if you were curious, the std namespace gives us access to stuff like cout and cin and all sorts
of cool shit. including the whole namespace is bad practice, though. i'll teach you how not to be
a noob later.
int main() { }
this is a function declaration (the brackets signify the body of the function), the main
function in any c++ program is conveniently titled main. int, as you've hopefully assumed,
means integer. when declaring a function or variable, you must give it a type. main is
always int, and you are a satanist if you use anything else. we'll get to types later.
cout << "hello world";
cout? trout? sprout? cout is c-out, or console output. if it's not occurred to you yet, this is
how you print stuff to the screen in c++. the two little arrows pointing towards cout (pay
attention to the direction!) mean the information is going into it, and not out of it. right now,
"hello world" is going into console output which means you'll see it on your screen.
return 0;
since you're not evil, and your main function is an integer type, it's got to have an integer
return value. saying return 0; means everything went okay and control is given
back to the operating system.
the very astute population reading this might've noticed a few semicolons. all statements
in c++ end in semicolons. a statement, for lack of better words, is pretty self explanatory.
if you're declaring something, or doing something rather important, it's probably a good idea to
stick a semicolon at the end. once you've learned a bit more, you'll never mess up with semicolons
unless you're heavily distracted.
page 1 page 2
page 3 page 4 page 5 page 6 page 7 page 8