Visual Studio terminates my console application too quickly

When I run my program in Visual Studio (just a Hello World application), it immediately closes and closes the console window, rather than waiting for me to close it manually. I went around this by including cin.get() at the end of the program, but my instructor just told me that I did not need to do this, and that he was able to run the same program last night, without having to enter an extra line.

Is this something in setting up Visual Studio?


Update

I tried using Ctrl + F5, but that just makes the console disappear even faster.

+1
source share
5 answers

This is by design, and your instructor is wrong. Try to run the .bat file from the folder view and you will get exactly the same behavior!

You can

  • Set a breakpoint

    Request user login via Console.Readline()

    Execute cursor

+4
source

Start in debug mode;)

+1
source

You can set a breakpoint and run the application in debug mode. This way, the IDE stops at the breakpoint and the window does not close until you continue executing the code.

+1
source

When testing Console.ReadKey() nice to have. Here is an example:

 namespace Foo { class Program { static void Main(string[] args) { Console.Write("The Console will close when it reads a key-input. "+ "Press a key to close"); Console.ReadKey(); } } } 
0
source

This will work for sure: in old Visual Studio 2010 and later, the system properties were grandfathered from a Windows system, however, 2010 and this property was configured or set to ti null. do the following and it will fix it.

To do this, select the project in the solution explorer on the right or on the left (perhaps it is already selected, so you do not need to worry about it). Then select “project” from the drop-down menus of the menu bar, then select “* project_name * properties”> “configuration properties”> “linker”> “system” and set the first property, the “subsystem” drop-down property to “console” (/ SUBSYSTEM: CONSOLE). "The console window should remain open after execution, as usual.

Are you ready to go NOW !!

0
source

Source: https://habr.com/ru/post/1242260/


All Articles