Activity Stream
48,167 MEMBERS
6787 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 8 of 8
  1.     
    #1
    Member
    Website's:
    Pirateview.org Gfxs.org StarkWood.org

    Default C++ Basics [Lesson 1]

    Welcome to the first tutorial on C++, i hope you are all eager to learn one of the most popular programming language!

    Getting Started:
    So, before starting, you need to have a program (a compiler), which you will use to write your codes. Below is a list of some free IDE (Integrated Development Environment), or simply programs, that you can use to write your c++ code.

    1. Dev Cpp
    Download:
    Code: 
    http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe
    2. Code::Blocks
    Download:
    Code: 
    http://www.codeblocks.org/downloads/26
    Well, you can download any of these software and try it out! From my part, i will use Dev Cpp, since i already have it installed on my PC.

    Once you installed your software (IDE) and it is running, make a new source page!

    In Dev cpp, you can click on the "new source page" icon or hit "alt + N"!
    Click on the 3rd icon.

    You will notice that you will have a blank page on your screen. This is where you can start typing you code!

    Before proceeding, let me give you a little trick, always save your work regularly, even if your code is incomplete, why am saying this? Because, sometimes you have to write long codes about thousands of lines and if you did not save your work, in the case of a power failure or your computer just got rebooted by itself, you will loose all your codes.

    Saving your file.
    File >> Save as >> Save type (Choose C++ Source file) and put a nice file name. Mine, i put "basic.cpp"!

    Well let get in the real coding now! Since C and C++ are considered as low level languages meaning, you would have to write many lines of codes for a simple instruction, there is something called Libraries, that will help us a lot in our work!

    Libraries.
    A library is simply a collection of codes that has already been coded by some geeks to allow us to write simpler codes. Lets take an example, suppose you want to write something on your screen. This simple process may involved lots of instructions, taking a text, sending it to your monitor, etc..Well, what a library can do? is that it will allow us to write a simple code to do this task, instead of us doing the whole complex stuffs.

    There are many libraries that you can use for writing software, for example there is OpenGl, SDL or DirectX Library for graphic stuffs. Windows library, for writing software under windows operating systems. The list goes on and on. For now, what we will use is the iostream library. This library offers many features but we will cover only the basic one you need to know here!

    What the iostream will allow you to do, is basically to display text and store or read files.

    So, the first thing we need to do is include this library in our program. Let's get to our blank source page and write the command to include the iostream library.



    No Copy, Paste for you! Write the code by yourself, that's how you will become a great programmer!

    To include a library, we write #include <Your library name here!>

    Comments
    Let me tell you another tip in programming, often you will need to write long amount of codes and sometimes, all these codes may seem fuzzy or you may forget what something you write about may do! A very good principle in programming, is commenting your codes. What are comments? well, its just a short note about something you wrote! Comments are ignored by your compiler, its sole use is for YOU!

    To write a comment in a single line, in c++, you write double forward slash followed by your comment. Now if you want to write multiple lines or paragraphs of comments, you write forward slash, an asterisk, your comment, another asterisk and another forward slash.

    Example:
    //This is a single line comment!

    /* This is a a veryy looong comment!
    Made by Alex!
    Date: 11 Dec 2010*/




    Next thing you need to know is about the main function.

    The main function.
    In all C or C++ programs, there is a main() function which must be written and all your coding must goes inside this function! What is a function? we will get to that in our later tutorials, but right now, all you need to know is that you need to write the following code.

    int main(){
    ALL Your coding goes here!
    }




    Hello world!
    The first thing you learn in most programming languages, is how to display a simple text on the screen! To do this we will use the following c++ command!

    std::cout << "Hello World";

    You have notice we have use std::count followed by a double less sign and the text we want to display in double quotes. Finally, you must write a semicolon. All statements(line of code) in c++ must end by a semicolon, that's the way you tell your compiler, "hey, this is a simple line instruction!".



    Well, lets try to run this piece of code now! Hit "F9" or click Execute >> Compile & Run (in Dev Cpp of course).


    ohhh, what happened? Well, nothing happened! Don't worry, if nothing happen, it does not mean the codes are wrong, it simply indicates that your code has been executed and finished already!

    Lets add another line of code, so as to tell the compiler "hey buddy, wait for a while, let me see what i have typed!". Add the following code:

    getchar() --> This will only tell the compiler to wait until an input is obtained, for example, until a keyboard key is pressed.


    Don't forget the semicolon as usual. That is very important and very often you will miss it!

    Now, lets try to re-compile this!


    You should get something like this black screen if everything went fine!


    NameSpace.
    hmm, that std:: stuffs looks kinda scaring. Actually, the really command to display a text is cout << "Your text here!", but don't forget, that command is present in your iostream library and you need to call it from the library! To call that command from the library, you use the std::, which is called a namespace. Well, this is not the proper definition of a namespace but you got an idea. Guess what? you could not use the std::, simply by adding the following line of code before your main function:

    using namespace std;



    If you try to compile your code again, everything will work as the previous code!


    Well, congratulations for your first c++ program! Hooray!!
    Don't worry, we got tons of other coding to learn more!

    Further Reading:
    Earlier computers had no visual display as you have on your screen right now, they had only that black screen you saw! What about visuals then? You may not believe it but for displaying a simple blank window on your screen, you would have to write some 70 lines of codes! :lol:, not that simple huh! Windows applications are rather complex and don't worry, it will be a piece of cake, when we get there in our later tutorials!

    Thanks a lot for reading this tutorial, i hope you did so and read it all!

    Download Source code:
    Code: 
    http://node.pirateview.org/1146/basic.zip
    Am taking a lot of time and effort to write these tutorials all by myself! I try to make it as simple as possible, for you people. So the least i can ask you, is to register on our site, Pirateview.org and to suport us by replying, posting feedback and participating in the board! We also need your contribution, if you feel, you can improve this tutorial!

    What is pirateview.org? is a simple board for sharing of knowledge and hanging out! feel free to check it out!

    Thanks and have a nice day!
    NucleA Reviewed by NucleA on . C++ Basics [Lesson 1] Welcome to the first tutorial on C++, i hope you are all eager to learn one of the most popular programming language! Getting Started: So, before starting, you need to have a program (a compiler), which you will use to write your codes. Below is a list of some free IDE (Integrated Development Environment), or simply programs, that you can use to write your c++ code. 1. Dev Cpp Download: http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe2. Code::Blocks Download: Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    movietvshow.net
    thanks alot for the great class

  4.     
    #3
    Member
    Website's:
    Pirateview.org Gfxs.org StarkWood.org
    Thnks. Source code added!

  5.     
    #4
    Member
    Hi,
    Wonderful post.
    thanks for sharing a nice post,
    Great work keep it up.

  6.     
    #5
    Member
    Website's:
    FileSonic.com
    Thanks for this post.......

  7.     
    #6
    Member
    Thnx NuClea!

  8.     
    #7
    Member
    main function returns an integer to the OS .
    so you have to add return 0;
    Coding Horror Fan
    I don't read PM's frequently .

  9.     
    #8
    Member
    You can aslo #include std; so you always dont have to use std::cout<<; and std::>>cin; .. All up a great tut


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 20th Oct 2012, 12:28 PM
  2. Basics of posting a thread with requiest
    By AllSolo in forum Graphics Area
    Replies: 6
    Last Post: 14th Jun 2012, 10:44 AM
  3. C# Basics I - Classes in C#
    By iFlames in forum Web Development Area
    Replies: 9
    Last Post: 29th Jun 2010, 05:33 PM
  4. Protect your Server. The Basics! (cPanel)
    By Storming in forum Technical and Security Tutorials
    Replies: 1
    Last Post: 16th Aug 2009, 07:36 PM
  5. PHP Tutorial (Loopy Loops) Basics
    By litewarez in forum Tutorials and Guides
    Replies: 0
    Last Post: 12th May 2009, 12:53 PM

Tags for this Thread

BE SOCIAL