Hello World, in C++. menu

Shout-Out

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 41
  1. #16
    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)
    i believe he meant to put int main()
    its just a typo


    Hello World, in C++.
  2. #17
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using a "return;" in a void function is how you jump out of the current function without executing any code below that point. "return;" and "return something;" are completely different.

    It's bad to add returns to void functions unless you want to explicitly exit out of the current function. (Say you hit an error, and don't want to execute any further code in the method)

  3. #18
    Glitchy's Avatar ★ Elder ★
    Reputation
    1277
    Join Date
    Jun 2007
    Posts
    985
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you think 4 line of code is bad for a hello world you should try ASM

    Here is a "hello world" app for a ti-83 calculator. I use to make games in this language, and I'm having to pick ASM back up for some PIC programming I'm doing.

    Code:
    .NOLIST
    #define   EQU   .equ
    #define   equ   .equ
    #define   END   .end
    #define   end   .end
    #include "ti83plus.inc"
    .LIST
    
         .org 9D93h
         .db ,$6D
          ld a,0
          ld (CURCOL),a
          ld (CURROW),a
          ld hl,text
          B_CALL(_PutS)
          ret
    text:
          .db "Hello, World",0
    
    .end
    end
    Last edited by Glitchy; 03-18-2008 at 02:52 AM.

  4. #19
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hence why nobody codes entirely in ASM. :P

    You'd commit suicide before you got anywhere with ASM.

  5. #20
    fattony's Avatar Member
    Reputation
    1
    Join Date
    Dec 2006
    Posts
    12
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    ++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++
    ..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.
    See, only two lines! Brain**** ftw

  6. #21
    Glitchy's Avatar ★ Elder ★
    Reputation
    1277
    Join Date
    Jun 2007
    Posts
    985
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Hence why nobody codes entirely in ASM. :P

    You'd commit suicide before you got anywhere with ASM.

    True a lot of PIC's not a days can wrap the asm code in C++

  7. #22
    Nebzor's Avatar Private
    Reputation
    1
    Join Date
    Apr 2008
    Posts
    3
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to add my purist taint, it should be as follows, and only as follows;

    Code:
    #include <iostream>
    
    int main(){
             std::cout << "Hello World!" << std::endl;
             return 0;
    }

  8. #23
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Hence why nobody codes entirely in ASM. :P

    You'd commit suicide before you got anywhere with ASM.

    I use ASM. ^_^

    Not to write entire programs in but inline in the DLLs I inject into WoW.

  9. #24
    Viter's Avatar Elite User
    Reputation
    410
    Join Date
    Aug 2007
    Posts
    2,153
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or you could write:

    Code:
    include <iostream>
    using namespace std;
    
    int main()
    {
    cout <<"Hello World"<<endl;
    system("pause")
    }
    Last edited by Viter; 04-12-2008 at 12:09 PM.



  10. #25
    Archdruid's Avatar Member
    Reputation
    1
    Join Date
    Apr 2008
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What compilers are you guys using?

  11. #26
    Sacred91's Avatar Member
    Reputation
    1
    Join Date
    Jun 2008
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using Microsoft visual c++ 2008 oder Code::Blocks

  12. #27
    kruz2's Avatar Member
    Reputation
    2
    Join Date
    Mar 2008
    Posts
    29
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry,
    Deleted.

  13. #28
    Recarver's Avatar Member
    Reputation
    1
    Join Date
    Aug 2008
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    C:
    #include <stdio.h>

    #include <iostream> // Incializing for windows

    int main(void)
    {
    printf("Hello World!");

    // Incializing for windows
    system("pause");

    return 0;
    }
    C++:
    #include <iostream>

    using namespace std;

    int main()
    {

    cout <<"Hello World!";

    // Incializing for windows
    cin.get();
    cin.get();

    return 0;
    }
    good luck

  14. #29
    unknown405's Avatar Member
    Reputation
    1
    Join Date
    Aug 2008
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh my god, this is obviously a thread for new coders trying to learn - PLEASE don't get them in the habit of using System("anything"). It's fine for HW assignments or meaningless little programs (like Hello World) but if you get them in the habit of using it, then they'll use it in their finished projects in the future. It's slow and it's a security risk, among other things it also tags you as a complete beginner. So to summarize, DONT USE SYSTEM("anything")!!

    I've put together an upgrade to Hello World that contains a good alternative to using system("pause") as well as posting a version where every line is commented because I know this is generally for beginners and another code snippet with no comments so the more advanced users still using system("pause") can read it more legibly. One more thing I would like to add is that yes, there are a lot of alternatives to system("pause") but remember that a lot more methods than system("pause") have some kind of flaw in them.

    Code:
    //HelloUser
    
    //Include necessary preprocessors
    #include <iostream> //Used for input/output (cin/cout)
    #include <string> //Used for string
    #include <limits> //Used for the numeric_limits
    
    //This prevents us from having to do "std::" before everything
    using namespace std;
    
    //Start of function
    int main ()
    {
    //String declaration for our input
    string str;
    
    //Outputs on the screen, "What is your name?"
      cout << "What is your name? ";
    //Here we take your answer to the question and convert it to our string declaration
    	cin >> str;
    //Outputs Hello%s, my name is Hello%s (with %s being input stream) then skips/ends line
      cout << "Hello " << str << ", my name is Hello" << str << endl;
    
    //Alternative to system("pause") which should NEVER BE USED!!
    	//This will ensure that the original ENTER was pushed after the final <<
      cin.ignore( numeric_limits<streamsize>::max(), 'n' );
    
    //Outputs on screen you can quit by pressing ENTER
      cout << "Press ENTER to quit!";
    
    //Alternative to system("pause") which should NEVER BE USED!!
      cin.ignore(numeric_limits<streamsize>::max(), 'n' );
    
    //Outputs the text below
      cout << "Bye, make sure you program me even better next time!!";
    
    //Return function telling our program that it exited with no errors
      return 0;
    }
    Code:
    //HelloUser
    
    #include <iostream> 
    #include <string>
    #include <limits>
    
    using namespace std;
    
    int main ()
    {
    string str;
      cout << "What is your name? ";
    cin >> str;
      cout << "Hello " << str << ", my name is Hello" << str << endl;
    
    cin.ignore( numeric_limits<streamsize>::max(), 'n' );
      cout << "Press ENTER to quit!";
    cin.ignore(numeric_limits<streamsize>::max(), 'n' );
      cout << "Bye, make sure you program me even better next time!!";
    
      return 0;
    }
    PS: I also just noticed that you had said for C++ to use cin.get() twice. That's, again, a completely improper way of going about it and doesn't even make sense. Your making the user have to press enter TWICE while giving him absolutely no notification of what he's supposed to do. Please learn to do it the right way now before you get in a bad habit of that.
    Last edited by unknown405; 08-26-2008 at 12:30 PM.

  15. #30
    breezy22's Avatar Member
    Reputation
    1
    Join Date
    Jul 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by unknown405 View Post
    Oh my god, this is obviously a thread for new coders trying to learn - PLEASE don't get them in the habit of using System("anything"). It's fine for HW assignments or meaningless little programs (like Hello World) but if you get them in the habit of using it, then they'll use it in their finished projects in the future. It's slow and it's a security risk, among other things it also tags you as a complete beginner. So to summarize, DONT USE SYSTEM("anything")!!

    I've put together an upgrade to Hello World that contains a good alternative to using system("pause") as well as posting a version where every line is commented because I know this is generally for beginners and another code snippet with no comments so the more advanced users still using system("pause") can read it more legibly. One more thing I would like to add is that yes, there are a lot of alternatives to system("pause") but remember that a lot more methods than system("pause") have some kind of flaw in them.

    Code:
    //HelloUser
    
    //Include necessary preprocessors
    #include <iostream> //Used for input/output (cin/cout)
    #include <string> //Used for string
    #include <limits> //Used for the numeric_limits
    
    //This prevents us from having to do "std::" before everything
    using namespace std;
    
    //Start of function
    int main ()
    {
    //String declaration for our input
    string str;
    
    //Outputs on the screen, "What is your name?"
      cout << "What is your name? ";
    //Here we take your answer to the question and convert it to our string declaration
    	cin >> str;
    //Outputs Hello%s, my name is Hello%s (with %s being input stream) then skips/ends line
      cout << "Hello " << str << ", my name is Hello" << str << endl;
    
    //Alternative to system("pause") which should NEVER BE USED!!
    	//This will ensure that the original ENTER was pushed after the final <<
      cin.ignore( numeric_limits<streamsize>::max(), 'n' );
    
    //Outputs on screen you can quit by pressing ENTER
      cout << "Press ENTER to quit!";
    
    //Alternative to system("pause") which should NEVER BE USED!!
      cin.ignore(numeric_limits<streamsize>::max(), 'n' );
    
    //Outputs the text below
      cout << "Bye, make sure you program me even better next time!!";
    
    //Return function telling our program that it exited with no errors
      return 0;
    }
    Code:
    //HelloUser
    
    #include <iostream> 
    #include <string>
    #include <limits>
    
    using namespace std;
    
    int main ()
    {
    string str;
      cout << "What is your name? ";
    cin >> str;
      cout << "Hello " << str << ", my name is Hello" << str << endl;
    
    cin.ignore( numeric_limits<streamsize>::max(), 'n' );
      cout << "Press ENTER to quit!";
    cin.ignore(numeric_limits<streamsize>::max(), 'n' );
      cout << "Bye, make sure you program me even better next time!!";
    
      return 0;
    }
    PS: I also just noticed that you had said for C++ to use cin.get() twice. That's, again, a completely improper way of going about it and doesn't even make sense. Your making the user have to press enter TWICE while giving him absolutely no notification of what he's supposed to do. Please learn to do it the right way now before you get in a bad habit of that.
    Yea I agree the cin.get() makes no sense. I would just return 0 and let it print the line. It's a hello world program the point is simple to print "Hello World".

Page 2 of 3 FirstFirst 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 07:43 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search