+ 7
How can we put pause function in program?
I'm writing a program in which the output has 256 line's, so i want to pause the output in after 20 line & then press any key to continues , this process is go on to the last line.
6 odpowiedzi
+ 4
system("pause");
If that dosent work
#include <conio.h> at top
cout<<"Click anything to continue\n";
getch();
+ 10
system("PAUSE") is used to pause the execution of a program. In pressing any key it will continue to output or whatever instruction you have given.
+ 8
Yes
+ 6
Muhammad Danial That actually depends on you , you need to sort it out in your algorithm
+ 3
In-program* you can hang for input. This forces the OS/process to pay attention to you (and tie up I/O handles, from the same pool as network sockets) until you answer. This is not ideal in the world of streams (anything recent): e.g., with forced program pauses you can't easily redirect your output to a file (or a pipe) and background threads hang.
That said...here's how to hang:
#include <conio.h>
_getch();
If you can, you should consider generating ALL of your output like usual. Then your program finishes normally, its output is sent to an output/memory stream and the program can quit (freeing up resources).
In this case you'd "pipe" its output to a stream manipulator like "more" (all OSs) or "less" (Linux, Android + others):
C:\>myprogram.exe | more
$ myprogram | less
This fills the screen with one page of content at a time. When you press enter/space, "more" always continues forward, while "less" can also go backwards.
* Note, "pause" is an external "DOS internal shell" command
0
If i want to pause the program after 20 line's. So how i have to put pause statement