locked
Closing of C++ windows before viewing RRS feed

  • Question

  • Hi

    I just began learning C++. It is interesting but i prefer using visual studio rather than other compilers. So the problem is that my exercise programs so far run fine on other compilers but on Visual Studio i cannot get to see the output as it closes almost immediately after execution. Please assist because it's demoralizing.

    Thank You. 


    • Edited by Molaseni Monday, November 7, 2016 12:02 PM
    Monday, November 7, 2016 12:01 PM

All replies

  • Just add a pause

    system("pause"); 
    or
    _getch(); 
    , etc...

    • Edited by Castorix31 Monday, November 7, 2016 12:14 PM
    • Proposed as answer by Baron Bi Tuesday, November 8, 2016 2:24 AM
    Monday, November 7, 2016 12:13 PM
  • Hello,

    there's no place for demoralizing, simply if I don't see no one command that can stop (pause/input via keyboard,loop,...) my code, after reach end of main it will close. Not demoralizing but true.

    Update: in case of using PAUSE, you must include iostream library for minimum, I think.



    • Edited by Duris_I Monday, November 7, 2016 12:53 PM
    Monday, November 7, 2016 12:48 PM
  • Or set a breakpoint on the last statement before the main() function returns.
    • Proposed as answer by Baron Bi Tuesday, November 8, 2016 2:24 AM
    Monday, November 7, 2016 12:58 PM
  • Is there some function in C++ like Console.Readkey() in C#, when the window closes after you press a button?
    Monday, November 7, 2016 1:27 PM
  • See Castorix31 response above.  Another option is getchar(). 
    • Proposed as answer by Baron Bi Tuesday, November 8, 2016 2:24 AM
    Monday, November 7, 2016 1:31 PM
  • Please vote for this suggestion if you want VC++ be friendlier to new students.

    Monday, November 7, 2016 6:53 PM
  • Thanks. It worked the wonder.
    Tuesday, November 8, 2016 11:53 AM
  • See Castorix31 response above.  Another option is getchar(). 

    Unfortunately, both these options are lousy. If unhandled exception strikes, the program may die immediately and will not arrive to the getchar().

    -- pa

     

    Tuesday, November 8, 2016 10:08 PM
  • See Castorix31 response above.  Another option is getchar(). 

    Unfortunately, both these options are lousy. If unhandled exception strikes, the program may die immediately and will not arrive to the getchar().

    We're talking about beginning programmers here.  Let's worry about unhandled exceptions after we have "Hello World" programs behind us.

    Even if such a feature as you desire existed the questions from beginners would only morph from "How can I keep my console window from closing?" to "How can I get my console window to close when my program ends?"

    '

    Tuesday, November 8, 2016 10:41 PM
  • Even if such a feature as you desire existed the questions from beginners would only morph from "How can I keep my console window from closing?" to "How can I get my console window to close when my program ends?"

    The answer then would be "uncheck that checkbox". 

    ( Python, being a better language for beginners than C++, has this issue covered. It is the -i switch. So simple. )

    -- pa

    • Edited by Pavel A Wednesday, November 9, 2016 6:06 PM
    Wednesday, November 9, 2016 6:02 PM
  • Even if such a feature as you desire existed the questions from beginners would only morph from "How can I keep my console window from closing?" to "How can I get my console window to close when my program ends?"

    The answer then would be "uncheck that checkbox". 

    ( Python, being a better language for beginners than C++, has this issue covered. It is the -i switch. So simple.

    But the questions will still be asked.  So what was gained?
    Wednesday, November 9, 2016 6:39 PM
  • Hi Molaseni,

    If your case has been solved, please help to mark answer.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Sera Yu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 10, 2016 6:34 AM