0

Is there a C++ equivalent of C#'s Debugger.IsAttached() method? (Windows-specific is fine with me.)

I have a console app that has a getchar() at the end of main() to keep the console window from closing when running from VS2012. I'd like to skip that step when running a debug build directly from the command line.

3Dave
  • 28,657
  • 18
  • 88
  • 151
  • https://msdn.microsoft.com/en-us/library/windows/desktop/ms680345%28v=vs.85%29.aspx – Hans Passant Jan 28 '15 at 23:43
  • @HansPassant the first link solves my problem. Your search Kung Fu is clearly superior to mine. Meta: There needs to be a "close" reason for "comments answered my question." – 3Dave Jan 28 '15 at 23:47
  • You asked the wrong question, you should generally be using [this technique](http://stackoverflow.com/a/13256385/17034) instead. – Hans Passant Jan 28 '15 at 23:49
  • I'm pretty sure that there is an option in Visual Studio setup that allows you to "keep the console window open". – Mats Petersson Jan 28 '15 at 23:49
  • @MatsPetersson I am inclined to believe you. However, my efforts to find said option have proved fruitless. And I really like pineapple. – 3Dave Jan 28 '15 at 23:51
  • Ok, so not COMPLETELY true. You get to press return to exit from the console window only if you are not actually debugging things... http://stackoverflow.com/questions/1775865/preventing-console-window-from-closing-on-visual-studio-c-c-console-applicatio – Mats Petersson Jan 28 '15 at 23:53
  • @MatsPetersson Yeah, but I want to run WITH debugging, I just want the app to not close the window when it's done. (**update** response to your prev comment) – 3Dave Jan 28 '15 at 23:54
  • Screw it - I added a command-line switch `keepOpen` to the debug command line parameters in VS. The app checks for that and does a `getchar()` if it is present. http://en.wikipedia.org/wiki/KISS_principle (And, it's cross-platform. Assuming platform includes `stdio`/`stdlib` support. :) – 3Dave Jan 28 '15 at 23:57

0 Answers0