hi guys can any one give me a program in c++ that if i ran it the cmd window will stop without using getch statement and conio.h header file, or tell me how ? plz thank you
program in c++ make the cmd stop without using getch()
Collapse
X
-
Tags: None
-
Put your program in an infinite loop.
Have the user enter a choice using whatever function you are happy with.
If the choice means exit, then break out of the loop. Otherwise, the program just idles in the loop. -
A system("pause") is the same as a getch() inthat you have to press enter to exit.
With a loop waiting on the user for a choice, you can put the code for getting the choice on a separate thread which you can monitor from main(). After a specified wait, main() can shut down the program without needing a response from the user.Comment
-
The infinite loop lets the program stop usally based on a menu:
while(1)
{
int choice = GetChoice();
switch(choice)
{
case ADD:
//call your "add logic"
break;
case DELETE:
//call your "delete logic"
break;
case etc.....
break;
case EXIT:
//call your cleanup logiv before exiting
exit(1); //stop the program. The only exit(1) in the code
default:
printf("Incorre ct choice\n");
}
}Comment
Comment