Stuart P. Bentley
Stuart P. Bentley

Reputation: 10675

Pausing after debugging command line application in Visual Studio

Is there a way short of writing a seperate batch file or adding a system call to pause or getch or a breakpoint right before the end of the main function to keep a command window open after a command line application has finished running?

Put differently, is there a way in the project properties to run another command after running the target path? If my program is "foo.exe", something equivalent to a batch file containing

@foo
@pause

Edit: added "or a getch or a breakpoint"

Upvotes: 1

Views: 4684

Answers (4)

Tom Leys
Tom Leys

Reputation: 19029

In C++

#include <conio.h>

// .. Your code

int main()
{
  // More of your code

  // Tell the user to press a key 
  getch();      // Get one character from the user (i.e a keypress)

  return 0;

}

If you are in a batch file, the command "pause" outputs "Press any key to continue" and waits for a keypress.

Upvotes: 0

Brian
Brian

Reputation: 118865

As you may know, at least in the C# project system, pressing Ctrl-F5 will add a "press any key to continue" to the end. But this doesn't run under the debugger, so I endorse the prior answer that said 'put a breakpoint at the end of main'.

Upvotes: 5

goldenmean
goldenmean

Reputation: 18956

If one has access to source code,

1.) Will adding a getch() added just before main ends, not puase the application executuion, while displaying the console applications console window as it was? Basically add any code which waits on a keyboard input

-AD

Upvotes: 0

tvanfosson
tvanfosson

Reputation: 532435

If running in the debugger (going by the title of your question), I just put a breakpoint at the closing brace in the main method.

Upvotes: 3

Related Questions