Gw Temp

Menu

Tutorial - 'A Beginners C++ Tutorial' by Guest

An item about Programming Languages posted on

Blurb

Your first ever C++ program.

Body

Hey, now that it's GW5, I'm gonna be more active. I decided to write a tutorial. Hey, if you guys like it, maybe I'll write some more. I dunno. This is a beginners C++ tutorial. This program will be a console (DOS) program. It's made for Windows, and I don't know what other OS it'll work on. This tutorial uses Dev-C++. You can download it at the site, http://www.bloodshed.net/devcpp.html. I'm scared to link it, 'cause I don't wanna look like an idiot who can't do HTML. I think you know how to run it. When it is run (I'm using version 4.9.8.0) you'll see a screen that looks like this: (Go to http://www.freewebs.com/revolutiongaming/opening screen.jpg to see) After you see that, click File->New->Project... Now click Console Application. DO NOT click any other button or this will all go terribly terribly wrong. In the bottom right-hand corner of the pop-up box, there should be a rectangle. :D 'tangular dude! B) click "C++ Project". Put a check on the box that says "Make default language". Let's name this project, "Tutorial" or something like that. Click okay. Ta-da! You should have a screen that says this:
#include
#include

using namespace std;

int main(int argc, char *argv[])
{

system("PAUSE");
return 0;
}

Does it have that? If you played with it and it doesn't have that, fix it back, or press and hold Ctrl+Z. Look to the very left of the window in Dev-C++. Do you see where it says "Project, Classes, and Debug"? Click on Project, and it'll give you a treeview of your project. Not much in the tree now is there? Just one thing, eh? Click the little plus next to the writing that says "Tutorial" HOORAY! The plus turned into a minus and now it also says main.cpp! At least if you did it smartly right. Like I said before, that is called a treeview, where you see a treeview (What a pun!) of your project. The right 3/4 or so of your screen is where you actually type your code. I can't think of what it's called, so I'll call it a typing box. Think of it as something similar to Microsoft WORD or something like that. Or Notepad. Or Dev-C++. It's like that in Dev at least. Ready to type some code? Alright, click on line 8, space 3. It should already be indented by 2 spaces, because that's the way Dev-C++ works. Just about, or maybe everything you ever type inside the main function will be indented 2 spaces. So on line 8, type in:

cout << "Hello, world!" << endl;

make sure you make it endl and not end1. I had a hard time figuring that out. Oh the Advil... ;_; With all the code typed in, it should say:

#include
#include

using namespace std;

int main(int argc, char *argv[])
{
cout << "Hello, world!" << endl;
system("PAUSE");
return 0;
}

If all is okay, press Execute->Compile & Run. Or, if you like shortcut keys, F9 will do. ;) When you press the button, it'll come to a "Save File" screen. The default file name is main, which is fine. Keep it there, and press enter or save. If all is well, it should come to a black console window that says:

Hello, world!
Press any key to continue...

If not, and there's an error, the compiler tries to tell you what's wrong. It'll tell you the line, and then you fix it! THEN your program should look like this:

Hello, world!
Press any key to continue...

Kudos! You just made your first C++ program! If this is good enough, I'll make more continuations of this C++ primer. :D Good luck with C++, and best wishes to all of you! :)