Advertisement

What is the command to stop the console window from automatically closing?

Started by April 13, 2002 08:06 PM
7 comments, last by mx1 22 years, 5 months ago
When the program is done executing the window closes but I need the window to stay open. I have heard of something you can set in Windows to make it stay open. Anyone know?
You can add this on Windows... It''s not ideal but it works.

system ("pause");

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Advertisement
also try Sleep(time) where time is the number of milliseconds you want to pause the program for.

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

I think I heard once about something in the registry that can be changed to make them stay open.
Anyone know what this is?
I don''t know the answer to that ... but what I do is easier when all you are doing is a rapid prototype of a console app ... I have a function:

void WaitForEnter(bool displayPrompt);

which simply prints a message (if the bool is true) "Press ENTER to close window" ... and uses get to wait for one character of input.

I place this function just above my return statement - and that way it holds the window open until you press ENTER ...

The reason for the bool is that, when the programs PURPOSE is to print output in a certain format, then I don''t want that extra promt screwing it up - cause I often like to redirect the output to a file ... but when I''m going interactive stuff ... or debugging, then I like the prompt to remind me ... or anyone I send the program to.
A simple call to getchar() in stdio.h does the trick for me.
Rhino2876
Advertisement
yeah call getchar() right before main()s return 0.
this keeps the window open until the user hits enter

[edited by - branhield on April 14, 2002 3:25:01 AM]
Me to Getch()
or cin<< input

Depending on what you are using
in Visual C++ 6.0 you can always press CTRL + F5 to build and run the program (if no errors) and it will be automaticly added (Press any key to continue)
True hackers are intelligent, they have to be. Either they do really great in school because they have nothing better to do, or they don't do so well because school is terribly boring. And the ones who are bored aren't that way because they don't give a shit about learning anything. A true hacker wants to know everything. They're bored because schools teach the same dull things over and over and over, nothing new, nothing challenging.

This topic is closed to new replies.

Advertisement