0

I wrote my own first little code, and was pleased to see it working while launching it from the Visual Studio. Then I, however, wanted to paste the .exe file to the desktop so I could run it without the need to run VS first, but it would not execute. The console itself opens for about a second, there is nothing in the console (there is supposed to be), and it shuts down immediately. Again, whole process takes about a second.

I have tried even doing the same with the basic "Hello world!" program VS gives as a default new project, but it was the same. Then I tried changing locations of the project, allowing it on the Firewall, turning off Firewall, turning off Smartscreen, allowing it in Malwarebytes.

Any help greatly appreciated, I feel I may have missed on something while installing the VS perhaps, but my C++ program works just fine.

Kajurant
  • 3
  • 1
  • 2
  • 4
    There's a good chance this is a duplicate of [Why is the console window closing immediately once displayed my output?](https://stackoverflow.com/questions/8868338/why-is-the-console-window-closing-immediately-once-displayed-my-output) If not, please [edit] the question and post your code. – 41686d6564 stands w. Palestine Aug 14 '20 at 11:42
  • 1
    Instead of copy the exe file and paste on your desktop. create a shortcut for your exe file then bring this shortcut in your desktop. – Hadi Mirzaei Aug 14 '20 at 11:45
  • Visual Studio automatically adds a console.readline for debugging purposes. However, this does not crossover with the exe so you would need to add a readline. – ChilliPenguin Aug 14 '20 at 12:14

1 Answers1

1

Add Console.ReadLine(); or Console.ReadKey(); on end of the code.

Like this:

static void Main(string[] args)
{
    //code here

    Console.ReadLine();
}

Read more here: Why is the console window closing immediately once displayed my output?