"Susan Rice" <sr****@cox.netwrote in message
news:8upqg.1030$lv.796@fed1read12...
I'm running a simple win32 console application and I want to impliment
a "Press any key to continue", so I print that prompt, and then
what's the easiest way to impliment reading any key? Do I use
'getchar', or 'gets', or some get function? or 'cin', or what's
an easy way?
What I want is the program to pause before exiting so the user
can read whatever messages there are before the console window
disappears.
Unfortunately, there is no cross platform way to do it. You can use an OS
specific call ( while ( !kbhit(), getch(), system("pause") etc.. in
windows ) or use a 3rd party library with such a call ( I seem to recall
boost has one ). The 3rd party libraries, as I'm aware, just take the their
function and call the OS specific code anyway.
If you are not concerned with cross platform operability, then use an OS
specific call.
What I do is the following code which is cross platform:
std::string wait;
std::cin >wait;
but this requires 2 key strokes. Any key and enter. Enter alone won't do
it. Any other key alone won't do it.
If your problem is with VC++ closing when you run a program before you can
see the output, one solution is to press ctrl-f5 to turn it instead of F5,
then it waits for a keypress before it closes the console.