This is a probably an embarasing question as no doubt the answer is blindingly obvious.
I've used Visual Studio for years, but this is the first time I've done any 'Console Application' development.
When I run my application the console window pops up, the program output appears and then the window closes as the application exits.
Is there a way to either keep it open until I have checked the output, or view the results after the window has closed?
You could run your executable from a command prompt. This way you could see all the output. Or, you could do something like this:
and this way the window would not close until you enter data for the
a
variable.Here is a way for C/C++:
Put this at the top of your program, and IF it is on a Windows system (
#ifdef _WIN32
), then it will create a macro calledWINPAUSE
. Whenever you want your program to pause, callWINPAUSE;
and it will pause the program, using the DOS command. For other systems like Unix/Linux, the console should not quit on program exit anyway.Right click on your project
select Console (/SUBSYSTEM:CONSOLE) in
SubSystem
option.Now try it...it should work
If you're using .NET, put
Console.ReadLine()
before the end of the program.It will wait for
<ENTER>
.A somewhat better solution:
at the beginning of your program.
Pros:
cin.sync(); cin.ignore();
trick instead ofsystem("pause");
)Cons:
Visual Studio 2015, with imports. Because I hate when code examples don't give the needed imports.