CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002
    Posts
    78

    Don't close the DOS output window

    Ok, I am running VC++ 6.0. How do I tell it NOT to close the output window of a Hello, world! style project. It is so fast I can't see anything.

    I've been searching through all tabs on each of the three of Options, Settings, and Customize menus. There appears to be nothing like that. I know on previous versions you could tell it to wait before closing (U-close the x box), and also you could supply command line arguments (which I don't care about here.)

  2. #2
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    One solution is to add, at the end of main, a call to getchar()...
    Code:
    #ifdef _DEBUG
    getchar();
    #endif
    Or you could call system( "pause" );:

    Code:
    #ifdef _DEBUG
    system( "pause" );
    #endif
    Don't forget to #include the appropriate headers...
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  3. #3
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Learn how the command prompt works.

    It executes code, and then closes once the program is done. It does this when you double click, or just outright execute a DOS program but not within a command prompt.

    Either open the command prompt, transverse to the directory and execute the executable within the command prompt.

    or

    Add this to your code
    Code:
    #include <cstdlib> //Include this header
    Then figure out where you want your program to pause (right before the end of the int main() function) and put:
    Code:
    system("PAUSE");

  4. #4
    Join Date
    Aug 2002
    Posts
    78
    I understand how it works.

    I know how to pause and sleep and things.

    I was asking if anyone knew how to tell Visual Studio to not close it. Versions prior to 6 (4 at least) have a specific setting to both add command line arguments when running and to not close the window when execution finishes. Evidently that has been removed, or at least well-hidden, in version 6, for no sensible reason.

  5. #5
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    I've not seen a setting that controls it, and I've not spent time to figure out what influences it, but sometimes (when debugging a console app with MSVC++ 6.0) after an app terminates the console will prompt for a keypress when debugging, and sometimes it will not. As a result, I tend to use getchar/system to ensure that the console only "disappears" when I'm ready for it to.
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured