+ 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.

2nd Jan 2019, 6:30 PM
Muhammad Danial
Muhammad Danial - avatar
6 odpowiedzi
+ 4
system("pause"); If that dosent work #include <conio.h> at top cout<<"Click anything to continue\n"; getch();
14th Feb 2019, 9:56 AM
Shahil Ahmed
Shahil Ahmed - avatar
+ 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.
2nd Jan 2019, 6:55 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 8
Yes
2nd Jan 2019, 6:57 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
Muhammad Danial That actually depends on you , you need to sort it out in your algorithm
1st Mar 2019, 10:37 AM
Shahil Ahmed
Shahil Ahmed - avatar
+ 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
2nd Jan 2019, 8:25 PM
Kirk Schafer
Kirk Schafer - avatar
0
If i want to pause the program after 20 line's. So how i have to put pause statement
2nd Jan 2019, 6:57 PM
Muhammad Danial
Muhammad Danial - avatar