473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

program in c++ make the cmd stop without using getch()

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
Mar 30 '13 #1
7 2266
weaknessforcats
9,208 Expert Mod 8TB
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.
Mar 30 '13 #2
try using
Expand|Select|Wrap|Line Numbers
  1. system("pause");
Mar 31 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Mar 31 '13 #4
But won't infinite loop just hang the program....?
Mar 31 '13 #5
@CasTLeVaNia...
Can you please elaborate your ques a little more?
Do you want to freeze your cmd screen for a while?
Mar 31 '13 #6
weaknessforcats
9,208 Expert Mod 8TB
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("Incorrect choice\n");

}
}
Mar 31 '13 #7
getline (cin,null); Is something like this what your after?
Apr 3 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Brian Roberts | last post by:
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The...
4
by: wenjie wang | last post by:
Greetings, I'd like to know is there any situation where your program could crash without reaching the breakpoint which you set at the beginning of main().
4
by: Michael Brown | last post by:
I would like to know if .NET has some sort of event that I can write a method for or something similar for when an application of my choosing starts.
6
by: tekmicha | last post by:
Hallo, I am a newbie in C and I have a question regarding C libraries. I got an application in C and I am trying to add some new features on it for my work. The problem is this application...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
2
by: samslists | last post by:
So I have a python program that runs a bunch of other programs....it then loops forever, occasionally executing other programs. To run each of these programs my python code executes:...
3
by: strangetorpedo | last post by:
The problem lies under where if (choice == '2') is...I need the program to keep prompting for num and den values as long as the user enters values less than or equal to 0. Once they are values...
0
by: neeraj1m | last post by:
Having multiple databases in my environment...As a DBA,I need to start and stop each DB individually weekly for backup.Can anyone please provide me the script or some command fuction to perform start...
1
by: Santek Moreli | last post by:
I am creating a simple program using a couple methods that will ask the user to input data (type int) until an empty string is entered, after which the output will be displayed. I need to figure...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.