Results 1 to 10 of 10

Thread: Beginers C++ Guide, The Right Way

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44

    Beginers C++ Guide, The Right Way

    Introduction

    Hello all you C++ wannbe's out there. Here is some help for you if your really starting at the bottom of the line. This guide will lead you off to a good foundation of C++ programing, thus I presume that from this you will get some motivation to fulfil your programers destiny! C++ , just like any other progrming language, requires alot of time and patience. So after this guide, you may start to notice what some people are writing in those confusing programing code you see in all those threads.

    Who is this guide intended to?

    This guide is basicly for the people the look around the C++ threads, and they are ashamed they cant ask a question for they might sound stupid because they dont know enough of the subject. Well this guide will just be the tip, the vey tip of the iceberg on what C++ has to offer.

    Chapter 1 / Your first hello world program

    Now, as in any other programing language, the best way to start is by a hello world program. A hello world program is basicly a little program you write so something will show on the screen, or you could call it screen display. First im just going to tell you how to create your own workspace. I do assume you have visual C++ or any other complier, so go in there, and try to clear your mind. Now you can see that in the middle there is a gray background, and on top alot of little confusiing buttons. On the very top, you can see file, go there, and choose new on the very top of the pop down menu. You will see a Box come up with confusing stuff like win32, ISAPI,ATL COM, and MFC. Dont worry, dont get nervus, just go over to the Win32 Application choose it and you wil see a dialog named Win32 Console Application - Step 1 of 1. This dialog is whree you set the initial attributes of the projects. In other words, you set its settings for the current project you want to have. Now just do the settings to your desire, which I will let you experiment on, and then click ok and viola, you got your self a workspace. Now whats missing? Files, you need to create a source file in the project you just created. dont be confused, it should make sense sooner or later.

    *HINT*

    Best way to learn anything is to experiment, and from your experiece comes the best lerning source, so I dare you to experiment a little in C++, get ur self a little bit more fimiliar.

    Creating and Adding Files

    Now the you have your project, you need to add new files to it. You can do that by selecting the menu project, add to project, new. That will display a dialog similar to the one you just created. Now do you see the tabs on top o the dialog screen? Your curreently under projects. Move to the tap that says Files. done?? good job. Now in files you will also see alot of confusing stuff. Dont worry about them, just scrool down to C++ Source File and create it. Thats all ladies and gentle men, you now have a complete workspace.

    The Code For Your First Program

    In the source files, you should type the following, I know you wont understand squat, but dont worry, all will be explained nearly after.

    PHP Code:
    /* Your First Program */

    /* Input Output Stream Header File */
    #include <iostream>

    /* Start */
    main (void)
    {
     
    std::cout << "Hello World" << std::endl;
     return 
    0;

    Now your going lke what the hell did he just do??? That should be what your asking, good, were on the right track. As you can see on the top /* enclosing with a */ , thats just to write comments. #include, to put it short is a preprocessor directive, on whcih you will dig the details later; for now, just think of it as a way to include from another file in your own file, in this case, the code iostream. Use the < > to encapsulate the header file, so you tell the complier to look on the defult include directory. If you use qutation marks, that means that the complier will use the project directory to look for the header files.

    *CAUTION*

    Header files usually have the .h extention. There are two iostream files, one with the .h, and one without it. I use the one without .h because it is the ANSI/ISO C++ standard. Using the iostream file instead of the iostream.h file makes yuor code compatible with many different compliers.

    You can seperate iostream into two like this: io stream. io stands for input output, and stream is the way u communicate with the computer files, screen, keyboard, and more.

    Now for main. When you try to run a console program, the opertaing system will call the main function. You are defining main in your program as accepting no arguments, or more correctly, no command-line argumetns. You do this by enclosing void, which means there are no paramiters inside tje parentheses following the main keyword. Sorry about the big and confusing worsds, but somethings cnot be explained without being confusing.

    Now lets look at the { } brackets enclosing the brogram. If you have brackets enclosing code, its called a code block. Thats all you need to know, besides to use them when ur writing programs.

    Now over to the confusing std::cout. cout (pronounced see out and is (c) console (out) output is the code that makes things appear on your screen. std is only a namespace. To be albe to use any member or method of the std namespace you need to use the :: (token) to specify that cout belongs with std.

    Now to strings. As you saw when I wrote "Hello World", notice the brackets around the words. If brackets enclose any words, they are Strings.

    Now to the << (insertion) operator. As the name says, it inserts whatever is on the right side of it, in your case, the string, into whatever is on the leftside, std::cout, and remember that cout displays anything with a insertion operator sign (<<) before it.

    Now to the endl, its basicly makes a new line endl can be seprated into two words also: end l end modifies l which is line, so its basicly endline, but can only be used as endl. You can also use /n to make a seperate line like this: std::cout << "Hello World/n";

    Last but not least the semicolen token. Never ever forget that. It terminates the end of the code thus giveing and end to it, without it, you will get errors upon errors, so make sure u use it in almost every line of code you have! except the #include <iostream> and main (void).
    The End

    Well ladies and gentlemen I hope u had fun and learned something from this, cuz I know I had fun. If by chance I might write another guide following up to this one, im not sure yet. But post any comments please onto this thread if this helped you or u got more questions. Thank you for your time.

    -Alex

    P.S. My email is [email protected] so email me for any particular reason you would have.

    P.S.S sorry for my spelling, didnt have time to recheck it all.
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    Ohhh my bad people, my email adress is [email protected], sorry I wasnt thinking when I wrote it there.
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    thats way too vc++ specific.. btw int return type on main, :: is the scope resolution operator, << is left shift (but overloaded in the streams). Other than that i think you go into irrelevant details rather than giving straight explanations..
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    { } are braces, as well.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    yeah im a vc++ guy, sorry I had to pump all that out in 20 minuts do to work but I shall re write it when im not so tired *yawn* until then, ZzZZZZzzZZzzZz
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And you use C-comments in a C++ program, why?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    They were not!! man, I made sure that my **** was right with my handu dandy game development book, and sure, come over it uses c++ and my comments relate right to them. I know its vc++ but it still is c++, so its all similar some way
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    C comments are still valid in C++.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    Yeah as you can tell im still a semi - newbie, but I like to teach as I learn, might be more of a learning experience for me... I just got into game development, so we shall see what I can do .

    But damn they make those books big. 900 - 1500 pages -_- I have to be reading for 3 days to read one of those bitches through
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Keep cool. It wasn't meant as critic, just a question. I didn't know you were a semi-newbie, sorry.

    Sure the C comments are valid, but C++ comments are simpler and they are, well, C++ comments. I would use them in a C++ HelloWorld...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width