Thread: hello world, please help

  1. #1
    Unregistered
    Guest

    hello world, please help

    Hey, I'm all new at this but I made my first "hello World" program. I wrote in the code and all the code is right, and i compiled it but when I try to open my program the Ms-DOS window pops up for like half a second then dissapears....after clicking real fast i can see that it says hello world in the window, but i can't keep it open!!

    please help
    [email protected]

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    be sure to include conio.h and before the 'return 0;' put getch();
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    #include <iostream>
    #include <conio.h>

    int main()
    {
    cout << "Hello World!!!";
    getch();
    return 0;
    }
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
        //all your hello world stuff
        _getch();
        return 0;
    }
    the _getch(); will wait for a keypress to continue.

  5. #5
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    Smile

    u must just be starting C++
    I remember that program.
    The one & only!!

  6. #6
    Unregistered
    Guest

    ya

    ya i am, yall got any good suggestions of where i should start? I'm only 13 but i'm seriusoly into computers and stuff so i'm very determined....

  7. #7
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    i would suggest starting with tic tac toe

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    unregistered.. you problem is your DOS Settings not your hello world app.

    do this

    go to start/ click run / type in "COMMAND"/ go to the directory containing your hello world app and then run it.. you should be all good
    SS3X

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    ss3x... adding a getch() is more mobile and compatible.

    restricting it to only work run from a dos window is pointless, when it only takes an extra line or 2 to make it mobile. ok?

  10. #10
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Hello? conio is not standard so anything from it is not portable.

    Do this:
    Code:
    #include <iostream>
       using std::cout;
       using std::cin;
    
    int main()
    {
       cout << "Hello world\n";
    
       cin.get();   // Pauses until enter is pressed
    
       return 0;
    }

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    biosx : i mean executable-wise it is portable.

    what good is it if you have to spend 5 seconds getting to dos every time when you could spend 5 seconds once writing getch(); ??? plus if it was distribute, way more mobile

  12. #12
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Just putting a getch() does not change anything. It is still a console application (notice I didn't say DOS application, b/c there is a difference between DOS programming and console programming).

    however way you code it:

    Code:
    #include <iostream>
       using std::cout;
       using std::cin;
    
    int main()
    {
       cout << "Hello world\n";
       
       cin.get();   // Pauses until enter is pressed
    
       return 0;
    }
    == and this ==

    Code:
    #include <iostream>
       using std::cout;
    
    #include <conio.h>
    
    int main()
    {
       cout << "Hello world\n";
       
       getch();   // Pauses until key is pressed
    
       return 0;
    }
    ... will still run in console windows without having to open up a cmd-term.

  13. #13
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Oh jeez.... just use conio for now; it's easier. It really doesn't matter which way you use. Go buy a C++ book not published by sams and not a _____ for dummies book.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The 7 New Wonders of the World
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 12-08-2006, 01:55 PM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  4. Too much to ask ?
    By deflamol in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 04:30 PM
  5. No More Technology After World War Three
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-20-2001, 07:02 PM