need C++ help

Discussion in 'Mac Programming' started by chris200x9, Jul 10, 2006.

  1. macrumors 6502a

    Joined:
    Jun 3, 2006
    #1
    ok I'm just learning c++ this question might be really simple but how do I get a program not to stay up untill i press escape, etc right now it just runs for a split second and outputs everything i programmed real quick then it disapears
    oh yea btw im on windows
     
  2. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    I'm assuming this is a console app, right? And I'm assuming you use Visual Studio? If so, this might help:

    I know this is the way things work under VS .NET 2003:

    * When you run the app without the debugger (Ctrl-F5 or Menu->Debug->Start Without Debugging) it will automatically stop, with the console window still visible, with the prompt "Press any key to continue." I think this is what you want. However, if you want to use the debugger...

    * When you run through the debugger (F5 or Menu->Debug->Start), console apps run through, and disapper, like you say. You can put a breakpoint at the end of your program to pause things (for example, put your cursor on the "return" line at the end of your main function and press F9 to place a breakpoint). When you run the app through the debugger, it will stop at the breakpoint, giving you a chance to look at things.

    * In any case (this should work for other environments) you could just call getchar() just before the return line at the end of your main function (or where ever you want to stick a pause in). The only downside is, you need to hit the enter key to move on (I don't think Esc or other keys will work). You may need to put #include <stdio.h> at the top of your source file in order to have access to getchar(). There are other ways to do this type of thing, but this is very easy.

    BTW, Don't take this the wrong way, buy why are you posting a Windows programming question on Mac Rumors? :)
     
  3. macrumors newbie

    Joined:
    Jul 14, 2006
    #3
    or you can just add
    Code:
    system("pause")
    at the end of your program(the last line of your code)
     
  4. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
  5. macrumors member

    rata911

    Joined:
    Jul 15, 2006
    Location:
    Uranus
    #5
    Err, the word "disappearing" grabbed my attention here. Did you double-click on your console-application?
    Try to start your application in the windows console (Start-->Run-->cmd) and cd to your folder and type the name of your program.exe.
    Did that help? :D
     

Share This Page