Thread: C++ Tutorial

  1. #1

    C++ Tutorial

    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".
    Last edited by frenchfry164; 10-20-2003 at 03:35 PM.

  2. #2
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    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.
    Such is life.

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    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.
    PHP and XML
    Let's talk about SAX

  4. #4
    ___
    Join Date
    Jun 2003
    Posts
    806
    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.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    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"
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    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.

  7. #7
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    Just for me? Wow.

    Tell you what, it looks way better.
    Such is life.

  8. #8
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Not bad, but go a little slower, beginners might be confused.
    Do not make direct eye contact with me.

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 02:49 PM
  5. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM