Thread: 'Hello World' - window disappears as soon as I run.

  1. #1
    Newbie
    Join Date
    Sep 2004
    Posts
    1

    'Hello World' - window disappears as soon as I run.

    I compiled and ran the 'hello world' program - we're all familiar with it I'm sure, but I have the following problem:

    When I run the .exe file the hello world window appears only for an instant, then disappears - I have no way of knowing what the window actually says. I can assume that it is saying Hello World, but how can I get it to stay on my screen?

    I am using the following code with Dev-C++:

    #include <iostream>

    int main()
    {
    std::cout << "Hello World!\n";
    return 0;
    }


    Any help is greatly appreciated. I wouldnt mind getting this stumbling block behind me so I can start to really learn.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well, that's a C++ program and this is a C Programming board, but you could add this line:
    Code:
    getchar();
    ...right above your return 0; line. When you run it just press ENTER to close the window.
    If you understand what you're doing, you're not learning anything.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Perhaps this is what you are after?

    [quzah mode]
    Curses! Foiled Again!
    [/quzah mode]

    ~/

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There are a few problems with you and your post:
    1) You didn't read the Announcements, like you were supposed to.
    2) You didn't use [code] tags, because of #1.
    3) You posted C++ code on the C board because you're a dumbass.^H^H^H^H^H^H^H^H^Hnot paying attention.

    Holy deja vu, Batman!

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    42
    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "Hello World!\n";
    std::cout<<"\n";   <-------------------- add this statement
    return 0;
    }

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by naruto
    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "Hello World!\n";
    std::cout<<"\n";   <-------------------- add this statement
    return 0;
    }
    That will print another newline but won't do anything about keeping the window open like the OP wants.
    If you understand what you're doing, you're not learning anything.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    But you could always add:
    Code:
        {char x; std::cin >> x;} //all nice and self-contained
        return 0;
    }


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User Chubz's Avatar
    Join Date
    Sep 2004
    Posts
    16
    Isn't, adding "cin.get ()" before the "return 0;" another solution, or is that used for something else????

    i'm new to programming too, but on the C++ forums I think I saw that part of code somewhere and on one of my programs it helped it show.

  9. #9
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by Chubz
    Isn't, adding "cin.get ()" before the "return 0;" another solution, or is that used for something else????

    i'm new to programming too, but on the C++ forums I think I saw that part of code somewhere and on one of my programs it helped it show.
    Yes, cin.get() will work too. The whole reasoning behind these different solutions is to ask the user for input. The input will be ignored, but it forces the user to press ENTER (like they'd normally do after typing some input) before the window will close. Any function that waits for the user to input something will be a solution to this problem.
    If you understand what you're doing, you're not learning anything.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I like this one:
    Code:
    for( ; ; );
    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User Chubz's Avatar
    Join Date
    Sep 2004
    Posts
    16
    Quote Originally Posted by itsme86
    Yes, cin.get() will work too. The whole reasoning behind these different solutions is to ask the user for input. The input will be ignored, but it forces the user to press ENTER (like they'd normally do after typing some input) before the window will close. Any function that waits for the user to input something will be a solution to this problem.
    Ah ok - nice try for a newb, at least!

  12. #12
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by quzah
    I like this one:
    Code:
    for( ; ; );
    Quzah.
    wouldnt that be a major waste of clock cycles?

  13. #13
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Yes.
    hello, internet!

  14. #14
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    lol!

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by sand_man
    wouldnt that be a major waste of clock cycles?
    No. That would be fully utilizing your processor, which otherwise would be wasting clock cycles doing nothing.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM