Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pausing the program. 1

Status
Not open for further replies.

PrograMan

Programmer
Jul 21, 2001
59
0
0
US
I'm looking for a way to pause my program without using that system("PAUSE") thing. I was once told that I can use getchar(), but that doesn't always work. Is there a better way? All I want is for the program to pause so that the user can view the displayed results and then to be able to hit Enter to continue.
 
#include<windows.h>
....
MessageBox(0, &quot;press ok to continue&quot; , &quot;&quot;, 0);

Ion Filipski
1c.bmp
 
Know any way to perform the same function within the console application instead of a window popping up? (BTW: that result was really cool. I didn't know that could be done.)
 
Try:
Code:
#include <conio.h>
int KbFlush()
{
  while (_kbhit())
    _getch();
}

int KbWait(const char* prompt = 0)
{
  int ch = 0;
  KbFlush(); // Flush all before...
  if (prompt)
    _cputs(prompt);

  ch = _getch();
  if (ch == 0 || ch == 0xE0) // Function or arrow key...
    ch = -getch(); //...its code negative value
  return ch; // Returns pressed key code
}
 
This should be easy and portable:
Code:
#include<iostream>
int main()
{
  std::cout << &quot;Press Enter to continue...&quot; << std::endl;
  std::cin.get();
}
 
i use this function:

#include <conio.h>

void PressAnyKey()
{
printf(&quot;Press any key to continue...\n&quot;);
getch();
}

Skute

&quot;There are 10 types of people in this World, those that understand binary, and those that don't!&quot;
 
you can also simulate a thread:

bool run = true;
while(run)
{
while(!kbhit());

switch(getch())
{
....
case 0:
switch(getch())
{...}
}
//to exit set run to false
}

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top