Program just quits

I'm am just running simple programs right now. For example the hello world code, but i never get to see if it works or not. After it compiles the black window comes up then it just quits. If i put in another command after like cin then the window stays up and i can see the hello world. What can I do to fix this.


Answer this question

Program just quits

  • paradoxium

    Hmm, let's compare our test apps. Mine is:

    #include <iostream>

    void main()
    {
    std::cout << "Hello World" << std::endl;
    std::cin.get();
    }

    And that keeps the console until I press <return>.

    How does your app look like. Might it cause an exception that crashes the app so it never reaches cin.get()

    --
    SvenC


  • JUNJIE.HONG

    You can also put a

    system( "pause" );

    at the end of your program.



  • hey_ian

    Hi,

    in native code use:

    std::cin.get() // wait until return is pressed

    in managed code use:

    Console::ReadKey();

    --
    SvenC


  • RoryD

    If i put std::cin.get(); at the begining of my program it waits to run the program until i hit enter, but when I put it at the end it just ignores it and quits anyway.

  • Drunkboat

    Thanks the system pause thing worked for me.

  • Pavel Burianek

    Little_Dice wrote:
    If i put std::cin.get(); at the begining of my program it waits to run the program until i hit enter, but when I put it at the end it just ignores it and quits anyway.

    Make sure you place the cin.get() prior to a return statement, or similar flow of control. If neccessary, place a breakpoint at the cin.get()-call and see if it's even executed.



  • Evan Mulawski

    use Debug--->Execute command to start you program

    After the program exit, the string "Press any key to countinue..." will be shown and the window will not close until you press any key


  • Program just quits