Microsoft Visual Studio problem with XP

bullion416

Senior member
Jun 17, 2001
658
0
0
I am running Windows XP Pro (SP1) and I have Mircosoft Visual Studio 6.0 Professional. As of right now I am only using Visual C++ for my programming class. Everything works fine, but after I have wirrten a working program and built it (complied and linked), the program will run fine in Visual C++, but if I try to run the .exe file from my computer without having Visual C++ loaded up, the program closes out the results of the program before they can be read. For example, Visual C++ adds in the feature where you press any key to exit the program. Well, for whatever reason, when the .exe is opened directly it will run the program fine, but it automatically closes the window without you even pressing any key to terminate the program. Any ideas on how to fix this? Thanks
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
It sounds like it's a console application, and you're running it from within windows. Windows will check the subsystem type (CUI for console user interface, and GUI for graphical user interface) when launching any PE formatted binary, and launch it appropriately. This isn't an error. The "press any key" that VC++ adds post-execution just allows you to more easily see the output.

Do one of two things:

1) Simply run it from the CLI. Just drop to a command line and run it...
2) Add a _kbhit() to the end of your program

 

PowerMacG5

Diamond Member
Apr 14, 2002
7,701
0
0
It doesn't matter what computer your running it on, whether VC++ is installed or not, the program will automatically exit, if run from windows, when return 0 is read. Their exist two ways around this: 1) Open the program from a DOS prompt, this will keep the display on screen; or 2) Add this line "cin.get()" (no quotes) the line before return 0. This will allow the program to be executed from windows, and will keep the output onscreen until the enter key is pressed.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: bullion416
what dou you mean, "run it from the CLI?
Programs > Accessories > Command Prompt
(or CLI = "Command Line Interface" if you love TLAs)

You can "CD" to the debug or release folder of your project then type myAppName.exe to run it.

e.g.

cd "c : \program files\microsoft visual studio\xxx\yyy\zzz\MyHappyApp\debug"
MyHappyApp



 

bullion416

Senior member
Jun 17, 2001
658
0
0
I tried the "cin.get()" command and it still exits out of the program. Isn't there supposed to be something written in the backets of that cin.get() command?