Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chris200x9

macrumors 6502a
Original poster
Jun 3, 2006
906
0
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
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
chris200x9 said:
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

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? :)
 

dogeye

macrumors newbie
Jul 14, 2006
5
0
or you can just add
Code:
system("pause")
at the end of your program(the last line of your code)
 

rata911

macrumors member
Jul 15, 2006
70
0
Uranus
chris200x9 said:
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

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.