+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 12

Thread: C++ Tutorial(1) "Hello World".

  1. #1
    Programming God thegamemaker has a spectacular aura about thegamemaker has a spectacular aura about thegamemaker's Avatar
    Join Date
    Nov 2009
    Location
    At the end of the rainbow.
    Age
    14
    Posts
    619
    Blog Entries
    1

    Talking C++ Tutorial(1) "Hello World".

    OK I can't stop the tradition so are first program in C++ will be of course "Hello World".
    OK let's get started.
    Code:
    #include<iostream> // This includes the files for input and output.
    
    int main() //Inside this is where the computer executes the code.
    {
    	std::cout << "Hello World" << std::endl; //This prints Hello World, cout pronounced C out sends Hello World to the console window.
    	                                         //endl which stands for endline puts us on the beginning of the next line if you want to stay on the same line then just don't add std::endl just the ";" after your text.
    	                                         // std stands for standard which just tells the computer that this is a standard operation.
    	
    	system("PAUSE");//This makes the window stay up without this the window would open and shut in a flash.(This is not a good way to do that I'll show you how to fix it next.)
    	return 0;//This ends the program.
    }
    Hope that was easy enough.
    Now I'm going to show you how to save some time righting a story or paragraph and a better way to keep the window open.
    Code:
    #include<iostream> // This includes the files for input and output.
    using namespace std; //This now includes the standard files(I think:{)so in are Hello World line we don't have to type std:: before cout and endl.
    
    int main() //Inside this is where the computer executes the code.
    {
    	cout << "Hello World" << endl; //This prints Hello World, cout pronounced C out sends Hello World to the console window.
    	                                         //endl  which stands for endline and puts us on the beginning of the next line if you want to stay on the same line then just don't add endl just the ";" after your text.
    	                                         
    	
    	cin.get();//This is a better way to make the window stay up(Note this only works if you include namespace std;
    	return 0;//This ends the program.
    }
    At first I didn't want to use the namespace std thing because I thought it was bad programming but it will save you a lot of work if you have a lot of sentences to type.

    Well I hope this tutorial helped you.
    (if you have any problems PM me or leave a visitor message sorry but I don't know how to make the code windows bigger)
    Last edited by thegamemaker; 12-14-2009 at 08:45 PM.
    My Web Site

  2. #2
    Newbie qasimbilal is an unknown quantity at this point
    Join Date
    Dec 2009
    Location
    Karachi, Pakistan
    Age
    23
    Posts
    8

    Re: C++ Tutorial(1) "Hello World".

    Nice, I will wait for your next posts
    thanks

  3. #3
    Administrator James.H is on a distinguished road James.H's Avatar
    Join Date
    Nov 2009
    Location
    London
    Posts
    674
    Blog Entries
    1

    Re: C++ Tutorial(1) "Hello World".

    Good first tut, look forward to your next one

  4. #4
    Programming God thegamemaker has a spectacular aura about thegamemaker has a spectacular aura about thegamemaker's Avatar
    Join Date
    Nov 2009
    Location
    At the end of the rainbow.
    Age
    14
    Posts
    619
    Blog Entries
    1

    Re: C++ Tutorial(1) "Hello World".

    Thanks,guys.
    My Web Site

  5. #5
    Newbie MicahN is an unknown quantity at this point
    Join Date
    Dec 2009
    Age
    20
    Posts
    2

    Re: C++ Tutorial(1) "Hello World".

    Good first tutorial!

    if i may make some suggestions though.

    Code:
    // std stands for standard which just tells the computer that this is a standard operation.
    std is the standard namespace where standard functions/operations are stored.

    Code:
    using namespace std; //This now includes the standard files(I think:{)so in are Hello World line we don't have to type std:: before cout and endl.
    this line tells the compiler that your are implicitly using the std namespace therefore you can call any function inside of the std namespace without having to explicitly let the compiler know what namespace you are using.

    also implicitly using a namespace is not bad programming but it has it's advantages and disadvantages.
    an advantage is as you have shown makes it so that you can use functions without having to prefix it with the namespace(std::cout changes to cout).

    but lets say you wanted to make your own function called cout if you were to use the namespace std then you would need to name your function something else. whereas if you did not implicitly use the std namespace then you could have your own cout function and keep the std::cout function.

    another disadvantage of implicitly using a namespace is code readability meaning how well humans can read your code.
    but if your just using the std namespace then you don't need to worry about that since the std is very common and easily recognizable.

    so implicitly using a namespace is all up to you the programmer.
    if you don't need to make a function that has the same name as in the namespace then go ahead and use it. it will only help you to code faster

    hopefully that all makes sense my grammar sucks

    like i said good tutorial look forward to more from you

  6. #6
    Programming God thegamemaker has a spectacular aura about thegamemaker has a spectacular aura about thegamemaker's Avatar
    Join Date
    Nov 2009
    Location
    At the end of the rainbow.
    Age
    14
    Posts
    619
    Blog Entries
    1

    Re: C++ Tutorial(1) "Hello World".

    Thanks for the info good to know.
    My Web Site

  7. #7
    Newbie LuiDaHottest is an unknown quantity at this point LuiDaHottest's Avatar
    Join Date
    Jan 2010
    Age
    20
    Posts
    18

    Re: C++ Tutorial(1) "Hello World".

    yup

  8. #8
    Programming Expert Bartimäus is on a distinguished road Bartimäus's Avatar
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    491

    Re: C++ Tutorial(1) "Hello World".

    Thank you! Nice Tut!

  9. #9
    Learning Programmer genux will become famous soon enough genux's Avatar
    Join Date
    Dec 2009
    Location
    Norwich
    Posts
    56

    Re: C++ Tutorial(1) "Hello World".

    nice post.. looking forward to the next ones

  10. #10
    Programming God thegamemaker has a spectacular aura about thegamemaker has a spectacular aura about thegamemaker's Avatar
    Join Date
    Nov 2009
    Location
    At the end of the rainbow.
    Age
    14
    Posts
    619
    Blog Entries
    1

    Re: C++ Tutorial(1) "Hello World".

    Thanks.
    My Web Site

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. "Hello World!"
    By GTghost in forum Introductions
    Replies: 7
    Last Post: 12-11-2009, 03:18 PM
  2. print "HELLO WORLD"
    By freeman in forum Introductions
    Replies: 8
    Last Post: 03-28-2009, 03:01 PM
  3. How could this "hello world" be wrong?
    By spadez in forum C and C++
    Replies: 5
    Last Post: 02-05-2009, 10:28 AM
  4. Java:Tutorial - "Hello World"
    By John in forum Java Tutorials
    Replies: 20
    Last Post: 12-23-2008, 08:52 PM
  5. Tutorial: PHP "Hello World"
    By Void in forum PHP Tutorials
    Replies: 4
    Last Post: 08-27-2006, 11:35 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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