How to run a program in a console from Visual Studio?

17,822

Solution 1

Instead of running it with F5 try running it with ctrl+F5. This way you cannot debug, but the window doesn't close when program exits.

Solution 2

Some suggestions:

  1. Set a breakpoint at the last line of main.

  2. At the end of main, add a call to wait for a keypress.

Share:
17,822
Inkbug
Author by

Inkbug

No need to waste Ink writing about me.

Updated on June 05, 2022

Comments

  • Inkbug
    Inkbug almost 2 years

    Possible Duplicate:
    C++ - Hold the console window open?

    I'm new to Visual Studio (actually Express), and I'm writing simple programs that write to the console in C++.

    How can one run the program in a console from Visual Studio?

    Directly running the program (ie. selecting Debug > Start Debugging) makes the program open a console window and then close.

    The way I'm doing it now is opening the command prompt and running the program from there. Can one do this from Visual Studio directly?