Sunday, August 2, 2009

How do I make applications run independantly of Visual Studio 2005?

I've been writing some C and C++ programs with it, but when I run the program by clicking on the .exe file, the console window closes as soon as the program ends, instead of letting me see the output. When run from inside VS, it ends with the "Press any key to continue . . . "





Do I need to add extra code, or what else can I do to have it run normally?

How do I make applications run independantly of Visual Studio 2005?
Your code ...is... running normally. It's a console program. Since you're double clicking on the exe (and not running from console), a console window opens up, the program runs, and the console window closes down.





So the correct way is to open up a console window yourself and run the program from there.





A kludge for development purposes is to ask for user input. You aren't actually going to do anything with the input, but by asking for input, the program window is forced to stay open. Something like cin.get() will do the trick (part of iostream) (http://cppreference.com/cppio/get.html ).
Reply:In Borland C/C++, the right way would be to call the getchar() function. You must include conio.h in order to call this function, but Visual C++ does not offer support for this function.





Another way would be to use sleep(time) where time is an integer that represents the amount of time to sleep (in miliseconds). Include time.h for this to work.

customer satisfaction survey

No comments:

Post a Comment