PDA

View Full Version : C++ Tutorial



frenchfry164
10-20-2003, 03:30 PM
I wrote a small C++ tutorial. I blabbered on way too much in it, and I just reread it and it looks like utter crap. I just wanna know what you guys think about it. I know I dragged it on and went into too much detail in parts, and I probably have a lot of typos, and the thing about MSVC is only true if you click execute from within the IDE, blah blah, but I just want to know if it does its job.

http://bludstayne.hostrocket.com/articles/cppbasics

edit: I know it looks stupid having Untitled Document as the title, but that's because you normally see it using frames, and it would instead say "Bludstayne Software".

Fountain
10-20-2003, 04:41 PM
Now let me explain how this works. You see all of those slashes in there? You know, the /'s? Well, if you put two of them at the beginning of a line, the rest of the line is commented out. That basically means that the compiler ignores the rest of that line. Comments are good to give the reader of the code little notes about the code. So the first real line of code is "#include <iostream>". Notice the pound sign? That basically tells the compiler that a special command for the compiler is coming up. There are many, many of these commands (they're called "preprocessor directives".) but the one we're using is called "include". Include takes a file and basically copy 'n' pastes its contents where the include command is issued. These files are called "header files" and have an extension of .h, unless they are part of the standard library. If a header file is of the standard library, no extension is required. Back in the days of C you needed them, but nowadays, if you put the .h at the end, you are actually including the C version of the header and not the C++ version of it. If you notice, iostream is part of the standard library, because it has no extension. Going farther down the code, you notice "int main()". C++ is called a modular object orientated programming language. Modular means it is based on functions. A function is basically a chunk of code that you can call in your program wherever needed. Don't worry about the object orientated part yet. Getting back to "int main()", this is basically declaring the function called main. Every C and C++ program has a function called main. If you don't have a main function, the compiler will throw errors at you. What is so important about main? Main is where the program starts. When you tell your OS to run your program, the OS calls this function. This is where the program starts up. I'll explain the "int" and the "()" when I get to variables. Some tutorials will tell you to use "void main()" BUT DO NOT DO THIS. It may compile and run, but there is more to having a working program than to just have it compile correctly. Always, I repeat, always use int main if you are using the C or C++ programming language. Back to what I was saying. The next line is just a open brace (a " is an open brace). This means that everything until the closed brace is part of this function. The next line might look weird. Let me explain. This is called a function call. The function we are calling is technically called "Overloaded operator <<" but it is commonly referred to as just cout. The "std" means that the function we are calling is in the standard namespace. Don't worry about that yet, just know that you need it to call cout. "cout" is a C++ class for console output. Don't worry about this yet either, just think "console output". The << is the function we are actually calling, but it is easiest just to remember "if I use cout to output text, I need to put << after it". Then you got a quotation mark. Everything until the next quotation mark is stored in the program as a string of text. When the program executes cout<<, it reads this string of text and outputs it. BTW, the "\n" in the quotes means to go to the next line. Next you got a semicolon. All function calls in C++ must end with a semicolon. This is due to the way the code is parsed by the compiler. Do NOT forget the semicolon, or the compiler will throw an error at you. This is the number one mistake people make when starting C based languages. The next line says "return 0;". This is called a "return value". I'll explain what it does when I get to variables, but in the function main, you have to return a value. Zero is commonly used for meaning "The program executed without any errors."


It actually looks ok ish, but ummm paragraphs would be good.

Waldo2k2
10-20-2003, 10:51 PM
Yeah, i'd say start over and make an outline of what you want to talk about first. Then pull your existing content into that outline. It would flow much better...it's all good though, some people can't write on the fly like that...actually most people can't so don't sweat it.

ZakkWylde969
10-21-2003, 05:33 AM
For a simple hello world program you went off onto way too many things. If you are breaking it down break down like.

Line 1- declares headers

Line2- empty. Made for easyness to read code. Compler ignores blank space and goes to next line of code.

major_small
10-21-2003, 07:23 AM
try doing what other c++ manuals do: put lines like "we'll go into further detail in chapter x" or "if you don't understand blah blah blah, don't worry"

frenchfry164
10-22-2003, 04:05 PM
Thx for your comments. I will be editing this tutorial some more, and I'll take your comments in consideration when making my next tutorial. I went a little too complicated for a simple hello, world program, but I'm trying to get them to learn cross-platform techniques from the start, so they use them wherever possible. I babbled on a lot of detail that wasn't required yet.

PS: I added paragraphs in that one section, just for Fountain.
PPS: I meant for this to be in the general discussion forum.

Fountain
10-23-2003, 11:40 AM
Just for me? Wow.

Tell you what, it looks way better. :)

Lurker
10-23-2003, 08:21 PM
Not bad, but go a little slower, beginners might be confused.

Glirk Dient
10-26-2003, 12:14 PM
Please leave it over detailed though.

I like to know every little bit I can, there are tons of C++ tutorials but few/none cover stuff in great detail as to why something is.