My console immediately closes when the user has done everything after entering the last step

Hi, guys!
my console doesn’t stay alive after the end of the compilation. Like, it just

IMMEDIATELY closes.

and closes itself. What I mean the last step is all. After any detail is entered the console immediately closes instead of showing “Press any key to continue…”

That quote comes too but then it closes immediately once I’m done compiling and finished with my program operations.

Please help! I’ve tried many suggested solutions from elsewhere and none of them seemed to work.

Can somebody who has had this problem and solved it give me a hand?
Any effective help will be much appreciated. After all, it annoys me that I can’t keep the console window alive, and in this chapter I can’t even see if the computer printed 1 or 0 after we print the character ‘y’ or ‘n’.

Thanks A LOAD!!!

1 Like

Hi @jack1.bat

In Visual Studio, have you tried going to Project >>BullCowGame Properties (or whatever you have called your game), Configuration Properties >> Linker >> System and under SubSystem put Console (/SUBSYSTEM:CONSOLE)? Apply, OK, try and rerun your code.

Are you running without debugging? It’s ctrl+f5 in visual studio. I regularly forget to run without debugging and the console window closes immediately when the program finishes.

1 Like

Thanks, @MikeT it works now after I press " ctrl-F5. " before I used to use the one present in the visual studio and it was with the debugger. It’s fixed now!

So I am getting this issue as well and neither one of the solutions listed above helped. Does anyone have any ideas as to what might be going on? I’m using visual studios enterprise 2017 if just to give reference to the year of the program. If anyone could help, I would appreciate it.

It’s not ideal, but as a work around you could put:

system("pause");

…just before your final return statement. At least on Windows, that should manually cause the “Press any key…” line to appear.

you must write
system(“Pause”);
before return 0;
in your program in order to wait for output
sample is

#include
using namespace std;

int main()
{
cout<<“Hello world”<<endl;
system(“Pause”);
return 0;
}

Privacy & Terms