0

I tried to run simple hello world in Visual Studio 2017 - empty project and empty console apps, but console closes instantly when i press ctrl + f5. Visual studio was working normal few days ago. I updated VS community edition but still have same problem. Tried different solutions like:Properties>Configuration Properties> Linker> System(Console (/SUBSYSTEM:CONSOLE)), tried system("pause"), but nothing is working. Does anyone has any solution to this?

The thing is, VS was working normal few days ago, and console app would run without getchar(), system() and similar functions(console would stay open).

  • I don't have a Windows machine nearby, but have you tried to `fflush(stdin)` and then use either pause, getchar etc? – Qubit Jun 27 '18 at 11:40
  • Is there anything in the output window (e.g. errors) – doctorlove Jun 27 '18 at 11:41
  • 1
    Can you find the executable of your application and run it manually from cmd? Do you see any output there? – Armen Tsirunyan Jun 27 '18 at 11:44
  • I don't think he knows if there's any output, VS tends to close the window REALLY fast, so if it's just a "hello world" he's expecting to see... – Qubit Jun 27 '18 at 11:44
  • @Qubit Flushing stdin is undefined. –  Jun 27 '18 at 11:51
  • when i double click exe file or files, it also closes immidiately, and wtf i cannot even open command prompt from windows – Nadan Marenković Jun 27 '18 at 11:53
  • If you can't open a normal command prompt, it appears that you have a significant problem in your system setup that is unrelated to your C++ coding. – Max Langhof Jun 27 '18 at 11:58
  • @NeilButterworth Yes, it is - as per the standard. But it does behave as one would expect. https://stackoverflow.com/questions/18170410/what-is-the-use-of-fflushstdin-in-c-programming – Qubit Jun 27 '18 at 12:00
  • thanks guys, but i found solution to the problem with cmd, – Nadan Marenković Jun 27 '18 at 12:04
  • If you still not found a solution, look at this article, [command prompt automatically closes after open](http://www.tomshardware.com/answers/id-1988202/command-prompt-automatically-closes-open.html). – Lion King Jun 27 '18 at 12:12

1 Answers1

0

Here is a way for C/C++:

#include <stdlib.h>

#ifdef _WIN32
#define WINPAUSE system("pause")
#endif

Put this at the top of your program, and IF it is on a Windows system (#ifdef _WIN32), then it will create a macro called WINPAUSE. Whenever you want your program to pause, call WINPAUSE; 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. This works with most of the versions of visual studio.

A_Singh7
  • 648
  • 7
  • 15