Hi!

How in C++ can we make a pause in the code, waiting for an ENTER?

regards

lol maybe this is what you are looking for

system("pause");

Yes, a more vulnerable and less portable solution is always better than a safe, portable one.
:lol: :rolleyes:

Yes, a more vulnerable and less portable solution is always better than a safe, portable one.
:lol: :rolleyes:

I dont get you, is this sarcasm?

I thought since he needed the pause without the cin.get() maybe this function would help.

I dont get you, is this sarcasm?

Yes.

I thought since he needed the pause without the cin.get() maybe this function would help.

I don't think the OP realizes s/he was handed exactly what s/he wants, but can't figure that out.

I didnt know sarcasm was allowed outside Geek's Lounge :-)

Well getting back to the topic, there are some cases where u just cant stop the console window from disappearing without the use of system ("pause") (just wanted to let u know that i have read the disdvantages of system function provided in the above thread).

Take for example a prog. that has many exit (0) and exit (1) calls to duck out in case of some failure like mem. allocation failure. In this case the calls to getchar () and cin.get() placed at the end of the program just wont happen since the exit (int) has already taken place.

So other than system("pause") do you know any other way the console screen can be stopped?

The "need" to pause is a symptom of the environment from which the program is run. And in cases in which you exit , you can also write code to pause there. The point is that you're missing the point.

The "need" to pause is a symptom of the environment from which the program is run. And in cases in which you exit , you can also write code to pause there. The point is that you're missing the point.

Maybe yes, thats why i explained in the previous post the dilemma i was facing.

Programs that have memory allocation in the code require the system to bail out in case of in case of some problem.

Since i used exit(1) i needed system("pause") to stop the console screen to see the output.

Do you know any way in which the prog can bail out when some error occurs without the use of exit (1) ?

Since i used exit(1) i needed system("pause") to stop the console screen to see the output.

Do you know any way in which the prog can bail out when some error occurs without the use of exit (1) ?

Change environment -- run it from the command line. Or register a function to run atexit . (Neither of which require system("pause"); .)

Write the error to a text log file before exiting ?

Yes good idea but it only solves the prob of displaying the error msg and not the prob of the screen staying so that i can see the output.

Your idea can be extended to displaying the output also in the log file
which is saved in HTML format like the VC IDE log files.

Change environment -- run it from the command line.

Sorry but i didnt understand this solution since never worked with command line compilers. If poss can u elaboreate on this. Thanks a lot.

Sorry but i didnt understand this solution since never worked with command line compilers. If poss can u elaboreate on this. Thanks a lot.

I'm not talking about the compiler, I'm talking about the executable. A console application run from a command shell does not have this issue. Done. And if you've got a GUI app, then this is moot anyway.

This article has been dead for over six months. Start a new discussion instead.