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

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

  1. #1
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    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 CommittedC0der; 12-14-2009 at 06:45 PM.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    qasimbilal is offline Newbie
    Join Date
    Dec 2009
    Location
    Karachi, Pakistan
    Posts
    9
    Rep Power
    0

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

    Nice, I will wait for your next posts
    thanks

  4. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    866
    Blog Entries
    3
    Rep Power
    14

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

    Good first tut, look forward to your next one

  5. #4
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

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

    Thanks,guys.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

  6. #5
    MicahN is offline Newbie
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    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

  7. #6
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

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

    Thanks for the info good to know.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

  8. #7
    Join Date
    Jan 2010
    Posts
    18
    Rep Power
    0

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

    yup

  9. #8
    Bartimäus's Avatar
    Bartimäus is offline Programming Expert
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    490
    Rep Power
    11

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

    Thank you! Nice Tut!

  10. #9
    genux's Avatar
    genux is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Norwich
    Posts
    79
    Rep Power
    8

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

    nice post.. looking forward to the next ones

  11. #10
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

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

    Thanks.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. INFECTION "Arcophage" Programmer needed for tutorial
    By Asyranok in forum Services for Buy/Sell/Trade
    Replies: 1
    Last Post: 12-08-2010, 08:43 PM
  2. Replies: 2
    Last Post: 11-01-2010, 11:52 PM
  3. Tutorial: PHP "Hello World"
    By Void in forum PHP Tutorials
    Replies: 5
    Last Post: 03-23-2010, 05:27 PM
  4. Java:Tutorial - "Hello World"
    By John in forum Java Tutorials
    Replies: 20
    Last Post: 12-23-2008, 06:52 PM
  5. Replies: 9
    Last Post: 01-09-2007, 07:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

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