Basics of C++

Discussion in 'Programming General' started by Raid500, Jun 20, 2008.

Basics of C++
  1. Unread #1 - Jun 20, 2008 at 11:20 AM
  2. Raid500
    Joined:
    Feb 11, 2007
    Posts:
    592
    Referrals:
    1
    Sythe Gold:
    0

    Raid500 Forum Addict

    Basics of C++

    Hello all, I am RAID and I am pretty good at programming/server coding/ect.. I am here to explain some basics of C++.

    Start out by downloading a C++ compiler (Dev-C++) from CLICK HERE This compiler is free which is great because most cost a ton!

    After you have downloaded it open it up and install.

    Picture of the important buttons:
    [​IMG]

    Now, open a new source file and you will notice that a box comes up. You will also notice that there is a few things already written in there.
    The first line: #include <iostream.h> Anything starting with a # tells the processor what to do. This is were all the declare files are found.
    The second line: #include <stdlib.h> This isn't as important as the first, so there isn't a point in explaining it.
    The fourth line: int main() This is where all the important thing in C++ start out working (after this line)
    The seventh line: system("PAUSE"); You will only need this if you use Dev-C++, all other programs don't need it.
    The eighth line: return 0; This makes the program stop.

    Now that you are more familiar with your compiler lets start learning some C++!

    The main difference between C++ and Java is that you can do more mathematical things with C++ than with Java.
    In C++ I use it a lot for math help (easy calculator). So now I'll teach you some of the signs.

    Code:
    + is addition
    - is subtraction
    * is multiplication
    / is division
    Code:
    +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=
    Those are the equal signs that you can use.

    Now:
    Code:
    x -= 5;
    This is actually x = x - 5; in C++. So in other words: The equal signs are stated to be used as so: x -= 5 would just be x = x - 5, nothing hard.


    Now to get you started making some simple C++ programs (not really programs, but simple "accessories")

    Code:
    //Name Program
    #include <iostream>
    
    int main ()
    {
      int name;
      cout << "What is your name?";
      cin >> name;
      system("PAUSE");
      return 0;
    }
    Now what this does.
    The //Name Program does nothing with the program since it isn't after the int main () and it has // before it, so keep this in mind, anything with // before it doesn't show up in your program. Now skip down to the int name; (we already discussed the others), this is declares a variable, int which is called name. The next line is what the program asks when you open it. It will ask What is your name? Then the next line you will respond and answer. The cout from the line before is what the compiler reads to make your program spit out what you put after it. The cin is what makes the compiler know to wait for you to respond.

    After you respond, the program closes. If you want anything more to talk with about to a bot (idk who would, but okay heres the rest)

    Code:
    #include <iostream>
    #include <string>
    
    int main ()
    {
      string string;
      cout << "What's your name? ";
      getline (cin, mystr);
      cout << "Hello " << string << ".\n";
      cout << "What is your favorite food? ";
      getline (cin, string);
      cout << "I like " << string << " too!\n";
      system("PAUSE");
      return 0;
    }
    The program would ask whats your name then it would ask another, now we are getting into more programming since we are using strings and making the bot copy what you say. The getline, is that bot copying your line.



    PS: IF YOU SEE ANY ERRORS: PLEASE TELL ME AND I WILL FIX IT!


    Thanks for reading,
    RAID
     
  3. Unread #2 - Jun 20, 2008 at 12:08 PM
  4. cazax
    Joined:
    Nov 13, 2007
    Posts:
    457
    Referrals:
    0
    Sythe Gold:
    0

    cazax Forum Addict

    Basics of C++

    From your last example:
    Code:
    getline (cin, mystr);
    You forgot to declare mystr as string.
     
  5. Unread #3 - Jun 20, 2008 at 10:21 PM
  6. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Basics of C++

    I see a direct contradiction.


    Secondly, define "Pretty good". Looks to me like you are just starting, from the word basics. Basics are everywhere, so I don't see why you would post this rather than snippets of useful code.
     
  7. Unread #4 - Jun 22, 2008 at 6:31 AM
  8. venom
    Joined:
    Sep 8, 2007
    Posts:
    2,499
    Referrals:
    1
    Sythe Gold:
    2

    venom Half psychotic sick Hypnotic
    Retired Sectional Moderator

    Basics of C++

  9. Unread #5 - Jun 22, 2008 at 10:21 AM
  10. use me
    Joined:
    Jun 8, 2008
    Posts:
    124
    Referrals:
    0
    Sythe Gold:
    0

    use me Active Member

    Basics of C++

    Venom1 that is a great eye! Good man.

    I once sailed with a man who had no arms and part of an eye....

    whatd i call him you say?

    Larry.
     
< Problem with my reverse function and its output! | Visual Basic download here! (Other Link's Don't Work? Try it here!) >

Users viewing this thread
1 guest


 
 
Adblock breaks this site