PDA

View Full Version : need C++ help




chris200x9
Jul 10, 2006, 08:01 PM
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
Jul 10, 2006, 08:56 PM
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
Jul 14, 2006, 02:26 PM
or you can just add system("pause") at the end of your program(the last line of your code)

slooksterPSV
Jul 15, 2006, 12:22 AM
All comments removed.

rata911
Jul 15, 2006, 07:26 AM
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