Reputation: 10673
When creating an console application (blank document) how can I get the "Press Any Button To Continue" to automatically show up?
Upvotes: 0
Views: 402
Reputation: 9926
There is no builtin function. However you can do a simple loop with kbhit() and getch(), like so:
#include <conio.h>
void main( void )
{
// Display your message here
for(;;)
{
while( !kbhit() );
if (getch() == 0x0D)
break; // Break on ENTER
}
// Continue on here
}
Adapted from http://support.microsoft.com/kb/44895
Upvotes: 1
Reputation: 340366
When you run a console program in the IDE using "Start Without Debugging" (Ctrl-F5
) you get the behavior you're looking for.
For some reason, when you start the program in the IDE under the debugger ("Start Debugging" or plain-old-F5
) you don't get that prompt when the program ends. If you just want to be able to see the last bit of what's in the console window when run under the debugger, you can set a breakpoint on the return
from main()
(or the closing brace for main()
).
Upvotes: 2
Reputation: 4062
system("pause") is definitely what you were asking for, but using it is very bad practice. Consider just using cin.get() at the end and press enter.
Upvotes: 0