Gw Temp

Menu

Tutorial - 'First C++ Program' by rpgspace

An item about Programming Languages posted on

Blurb

The basic Hello World program, oh my!

Body

Ok, for all of you who dont know what c++ is, it is a type of programming that you do everything by scratch. There is no drop and drag like rm2k or Game Maker. All computer games you have bought and played are probably made using c++. Anyway, this tutorial tells you how to make a program that says "Hello World". You also need a compiler to make a .cpp into an exe. I use dev compiler. That can be found at http://www.bloodshed.net, look for free compilers.

Ok, first we have to use an include. This includes a .h to allow you to do something by coding. We will use iostream.h, this is used to make something show on the screen.the syntax is:

#include

Next we have to use int main(), you need this in all programs for it to work properly. ok, so so far you should have:

#include

int main()

ok, have it good. After int main() you need brackets({ and }) to tell the compiler what is in the program. so the syntax for this would be:

int main()
{
}

ok, good. Now you put whatever you want inside the brackets. To make words show on the screen you would type in cout. The syntax is:

cout << "whatever you want to appear here"

ok. I forgot one thing which is to put ; after everything to show the compiler you are going to the next line, except for the includes. So far, you should have:

#include

int main()
{
cout << "Hello World";
}

Ok, now this would not work because you need to return. You would use:

return 0;

at the end.
ok, so now we should have:

#include

int main()
{
cout << "Hello World";

return 0;
}

Ok, now go ahead and put that through your compiler.

All you see is a black dos program flash right? All you need to do to fix that is inlclude cstdlib and the a system pause at the end. Okay, now the code should look like:

#include
#include

int main()
{
cout << "Hello World";

system("pause");

return 0;
}

Now go ahead and run that through the compiler. You can actually see the words right? Cool, well, that is that for this tutorial, expect more soon from me.