Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 5 of 5
  1. #1
    Grunt
    Sdyess94's Avatar
    Join Date
    Jan 2009
    Posts
    36
    Post Thanks / Like
    Rep Power
    16
    Reputation
    60

    [C++] Hello World


    Register to remove this ad
    As always, we will start with a Hello World console application. This is seen to be many peoples first coding experience and will more than likely remain that way for quite some time. Let's get started.

    Lets create the frame of the application:
    Code:
    #include <iostream>
    
    void main()
    {
     using namespace std;
     cout << "Hello World" << endl;
     cin.get();
     }
    Unlike most hello world tutorials, we used void instead of int. I figured it was too early to have you ponder on returns.
    So let's break this into small pieces.

    Code:
    #include <iostream>
    This as you can obviously see, includes the iostream file.
    The angle brackets (< and >) refer to a standard header which is part of the C++ library.
    iostream suggests input/output instead of random access or other things.

    Next, we have:
    Code:
    void main()
    If you have read my java tutorial, you will somewhat understand this since Java is created from Smalltalk and C++.
    void means the function doesnt have to return anything. Normally people use int main() in which they have to return an integer. we named the function main because the first thing a program does when it runs is search for the main function to run off of.

    Code:
    using namespace std;
    Without this part, the script would look like this:
    Code:
    std::cout << "Hello World" << std::endl;
    std::cin.get();
    It pretty much just makes it simpler and less for you to read and make it more organized. This namespace isnt always used though, beware.

    Code:
    cout << "Hello World" << endl;
    cin.get();
    Final part here.
    Code:
    cout << "Hello World" << endl;
    cout << is going to output whatever is after the "<<". For example, you could do
    Code:
    cout<< "roflcopters";
    Your application will have an output of "roflcopters".
    The second part, where it has <<endl, ends the line, and the next piece of output will begin on the next line. And then you use a semicolon(;) to end the statement.

    Finally we have:
    Code:
    cin.get();
    I've included to this to keep your application open. Without it, it would close.

    This tell the console to get the next piece of input, which should be the enter key. Once you press that, it'll close.

    Thanks for reading my tutorial on the Hello World application written in C++.

    If you have any questions feel free to PM me.


    › See More: [C++] Hello World

  2. #2
    Founder
    Apple's Avatar
    Join Date
    Jul 2008
    Location
    HeaveN
    Posts
    15,916
    Post Thanks / Like
    Rep Power
    10
    Reputation
    295
    nice one & wb by the way





  3. #3
    Banned

    Join Date
    Sep 2009
    Posts
    90
    Post Thanks / Like
    Rep Power
    0
    Reputation
    103
    Quote Originally Posted by Sdyess94 View Post
    Code:
    #include <iostream>
    
    void main()
    {
     using namespace std;
     cout << "Hello World" << endl;
     cin.get();
     }
    Code:
    cin.get();
    is not needed at all. If you use visual studio then just press ctrl + f5 to execute the application.

    If you dont have visual studio, then i suggest that you use
    Code:
    system("pause");
    instead.

  4. #4
    Banned

    Join Date
    Sep 2009
    Location
    In My Computer
    Posts
    76
    Post Thanks / Like
    Rep Power
    0
    Reputation
    52
    sdyess strikes again. not bad!

  5. #5
    Beginner
    DeVTeo's Avatar
    Join Date
    Nov 2010
    Location
    Bulgaria
    Posts
    9
    Post Thanks / Like
    Rep Power
    14
    Reputation
    1

    Register to remove this ad
    This tutorial for beginners in C++ programming is good




  6. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

 

 

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 05:40 PM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org