2

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?

Community
  • 1
  • 1
Inkbug
  • 1,682
  • 1
  • 10
  • 26
  • 1
    Sounds like you've already answered your own question. You have a console program, and when you run it, it appears in a console: problem solved. If you want the console to remain visible after your program completes, then that's another matter, separate from what you asked. Maybe you want the question about [holding the console window open](http://stackoverflow.com/q/1908512/33732), or the one about [keeping it open while debugging](http://stackoverflow.com/q/5066057/33732). – Rob Kennedy Aug 13 '12 at 15:16
  • @RobKennedy - I don't think so. Running application with `ctrl+F5` will hold the window opened, while debugging (just pressing `F5` or `Debug->Start Debugging`) will not. – Kiril Kirov Aug 13 '12 at 15:17
  • How does that disagree with what I said, @Kiril? – Rob Kennedy Aug 13 '12 at 15:20
  • @RobKennedy - maybe I have misunderstood you. What I understand from you comment is, that you _need_ to add `std::cin.get();` (for example), to hold the window opened and that it can't be done in another way. Sorry, if I have misunderstood you :) – Kiril Kirov Aug 13 '12 at 15:21
  • I never suggested *how* to keep the window open, @Kiril. I merely linked to questions that ask about how to do that because this question, about how to have the console appear at all, was answered *in* the question and probably isn't what Inkbug meant to ask about at all. Once Inkbug clarifies what he or she really wants, we can probably close the question as a duplicate of one of the questions I linked to. – Rob Kennedy Aug 13 '12 at 15:26
  • @RobKennedy Sorry. You're correct. I voted to close this. – Inkbug Aug 13 '12 at 15:52
  • @RobKennedy - okay, okay, no offense. – Kiril Kirov Aug 13 '12 at 16:41

3 Answers3

4

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.

Andrzej
  • 5,027
  • 27
  • 36
1

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.

Andriy
  • 8,486
  • 3
  • 27
  • 51
0

If you've setup any breakpoints, the program should pause when they are hit.

If not, either running or starting the application will of course exit if you're not waiting for any user input or for some event.

You can step into the application with F10. This will set the debugger to the first line of main and you can continue stepping through the app.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625