| | |
How to hide the "Press any key to continue?"
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I assume you're using 
The usual recommendation for pausing a program from an IDE that terminates the hosting console when the program ends is to ask for input. For example, the following code won't terminate until you press the Enter key:
You'll eventually have problems with existing data in the stream causing this not to work, but we have a sticky on this forum that teaches you how to deal with that.
system ( "PAUSE" ) . My first inclination is to say that this solution is a bad idea anyway, and if it doesn't do exactly what you want, that's all the better for convincing you not to use it. 
The usual recommendation for pausing a program from an IDE that terminates the hosting console when the program ends is to ask for input. For example, the following code won't terminate until you press the Enter key:
C++ Syntax (Toggle Plain Text)
#include <iostream> int main() { std::cout<<"Hello, world!\n"; std::cin.get(); }
Last edited by Narue; Jan 17th, 2009 at 9:11 pm.
New members chased away this month: 4
You can also do:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> int main() { std::cout << "HELLO WORLD!!!!!!!111"; getch(); }
Last edited by TheBeast32; Jan 17th, 2009 at 9:41 pm.
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
--Martin Golding
•
•
Join Date: Mar 2008
Posts: 1,491
Reputation:
Solved Threads: 123
For a windows solution, you could try this which will allow the user to press any key to continue (not just enter): To remove the message, simply call it like this.
C++ Syntax (Toggle Plain Text)
void Pause(char *message = "Press any key to continue . . . ") { std::cout << message; HANDLE hStdin; DWORD cNumRead; INPUT_RECORD irInBuf[1]; if ( HANDLE(hStdin = GetStdHandle( STD_INPUT_HANDLE )) == INVALID_HANDLE_VALUE ) return; while ( true ) { if (! ReadConsoleInput( hStdin, irInBuf, 1, &cNumRead) ) return; for (DWORD i = 0; i < cNumRead; ++i) if ( irInBuf[i].EventType == KEY_EVENT && irInBuf[i].Event.KeyEvent.bKeyDown ) { std::cout << '\n'; return; } } }
C++ Syntax (Toggle Plain Text)
Pause("");
Last edited by William Hemsworth; Jan 18th, 2009 at 3:28 pm.
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- "topantispyware" virus (Viruses, Spyware and other Nasties)
- Please help with " rdriv.sys" virus (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Problem with #define
- Next Thread: Ugh! I'm beginning to hate this course
Views: 1207 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






