Hello World, in C++. menu

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 15 of 41
  1. #1
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hello World, in C++.

    Like all the others, here we go!

    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "Hello world\n";
    return 0;
    }
    The first line, "#include <iostream>" includes the library iostream, which is used later, for the command "std::cout". If we removed it, we would get that "std" isn't an class or namespace, and that "cout" has an undeclared identifier (std).

    The next line, "int main()" creates the main function, this function is needed in EVERY C++ program.

    Next line, "{" shows where the main() function start.

    Next line, "std::cout << "Hello world!\n";
    "std" is the identifier for "cout", without "std::" infront of it, we would get a nasty error. We could actually have added "using namespace std;" after "#include <iostream>", and we wouldn't have to use "std::" anywhere in our program. "cout" is used to show something on the screen. "<<" Those two are needed before we show something on the screen, and the next i'm sure you can guess what does. The "\n" part specifies a line-break. Instead of "\n", we could've used "std::cout << "Hello world!" std::endl;" which makes it end the line (endl = end line).
    The next line, "}" closes the main() function.
    That was the legendary Hello World program in C++.
    Last edited by MaiN; 10-02-2008 at 12:09 PM.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

    Hello World, in C++.
  2. #2
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All that just for hello world? o.0

    Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.

  3. #3
    Marlo's Avatar Banned
    Reputation
    84
    Join Date
    Jul 2006
    Posts
    2,453
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ReidE96 View Post
    All that just for hello world? o.0

    Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.
    but then again who the **** needs a spinning cube?

  4. #4
    RyudoP's Avatar Member
    Reputation
    58
    Join Date
    Nov 2007
    Posts
    86
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Think it'd be good to add a return 0; at the end aswell. Most compilers will work fine without it (they just assume the program ends after there aren't any more statements), but others require it.

  5. #5
    Functions's Avatar Banned
    Reputation
    10
    Join Date
    Dec 2007
    Posts
    206
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lololol.... This is an LOL moment LOL MOMENTS!!!!

  6. #6
    Pragma's Avatar Contributor
    Reputation
    261
    Join Date
    Feb 2007
    Posts
    630
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.
    the reason why C++ is so leet is because how accurate it is, if you can make a spinning 3d cube with four lines of code there proly isnt too much variety in that language.


  7. #7
    **Sweeny**'s Avatar Member
    Reputation
    33
    Join Date
    Dec 2007
    Posts
    282
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If this is for begginers you shouldn't confuse them by shortening the c++ script down you should keep it like
    #include <iostream>

    using namespace std;

    int main()
    {
    cout<<"Hello World!\n";
    cin.get();
    }




  8. #8
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhmm, your's just as long as mine..
    And Reid, you ****ing have to enter a full-screen game-type mode, to even program DarkCode.... Which sucks, kinda.
    And WTF, just because you can make a spinning cube in 4 lines, doesn't mean it's that good, what about making a language which can make spinning cubes like this:
    "CREATE CUBE -> SPIN"
    So, if i create a language which could do that it would be the best language in the world?
    Last edited by MaiN; 03-15-2008 at 12:29 PM.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  9. #9
    **Sweeny**'s Avatar Member
    Reputation
    33
    Join Date
    Dec 2007
    Posts
    282
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And Reid, you ****ing have to enter a full-screen game-type mode, to even program DarkCode.... Which sucks, kinda.
    And WTF, just because you can make a spinning cube in 4 lines, doesn't mean it's that good, what about making a language which can make spinning cubes like this:
    "CREATE CUBE -> SPIN"
    So, if i create a language which could do that it would be the best language in the world?
    HAHAAAA NICE!!! pwned reid

  10. #10
    -Lex's Avatar Banned
    Reputation
    88
    Join Date
    Jun 2007
    Posts
    946
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    msgbox (0, "Hello", "World")
    Autoit ftw

  11. #11
    EcHoEs's Avatar lol why u mad
    Reputation
    374
    Join Date
    Sep 2006
    Posts
    1,647
    Thanks G/R
    3/1
    Trade Feedback
    2 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then again who would want app to say "Hello world"


  12. #12
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EcHoEs makes a good point.

    And MaiN, if that was all your language could do I'd be worried.

    insanesk - No, you can be really specific with it. You just use some other commands.

  13. #13
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're all missing the point of what C++ and this program is about.

    "Hello World" is the traditional first program you do in any language.

    DarkBasic is more of an easy way to do not so complex VISUAL programming.

    C++ is a language where there are no limits as to what you can do. Literally.

    The fact that C++ allows you to manually control the memory your application uses is already a main point why this language has a small heads up over some other languages. Not to mention 90% of the games you play are not made in DarkBasic, but a combination of C++ and C. (Yes sometimes you need some managed code which is easier to do in C than C++)

    Now, with my ranting out of the way, please stay on topic. No need to bash a language because it takes 4 lines to write a hello world app.

    Ryudop, if you're still using a compiler that requires the 0, you should seriously look into getting a new compiler. The last time I used a compiler that required that was back in 97.

  14. #14
    RyudoP's Avatar Member
    Reputation
    58
    Join Date
    Nov 2007
    Posts
    86
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Ryudop, if you're still using a compiler that requires the 0, you should seriously look into getting a new compiler. The last time I used a compiler that required that was back in 97.
    Yeah i know it isn't really needed, but it's a good habit to always include a return statement in non-void functions. (or even in void functions)


    *edit*
    @post below, void indicates that no value is returned, but you still return to the function that called you.. so just 'return;'.

  15. #15
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you add a return statement in a void function? The sole purpose of a void is to NOT return anything. Most compilers would throw an error about adding a return in a void function...

Page 1 of 3 123 LastLast

Similar Threads

  1. "Hello World" to making bots & hacks
    By Hi on helium in forum Programming
    Replies: 5
    Last Post: 11-14-2009, 07:33 PM
  2. Hello World!
    By Pragma in forum Programming
    Replies: 8
    Last Post: 03-24-2008, 06:32 PM
  3. Hello World, in DarkBASIC
    By ReidE96 in forum Programming
    Replies: 0
    Last Post: 03-14-2008, 06:26 PM
  4. Hello world !
    By tttommeke in forum Programming
    Replies: 4
    Last Post: 03-09-2008, 10:53 AM
All times are GMT -5. The time now is 10:01 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search