line buffering . In this case, the standard I/O library performs I/O operations when a newline character is encountered in the input and output. This allows us to output one character at a time, but only after a row has been written does the actual I/O operation. Row buffering is typically used when a stream involves a terminal.
First example: (Hello World)
Here, when we are not behind the Hello world, there is no Hello world in the results;
And when we add to it,
The result is this:
This is why, this is because of the existence of the buffer zone. The content is stored in the row buffer before it is printed on the screen. The content is output only if \ n is recognized.
Second Example: (Magic progress bar)
Speaking of the progress bar, we are all familiar with it. For example, like this:
How can such a progress bar be implemented in code?
To make a simple analysis, first we have to output the progress we've made, and the rest, and we have to show the percentages.
The code implementation is as follows:
Progress_bar is defined as a 102 space to store each progress;
Ch[] Indicates the buffering effect when the progress occurs;
' # ' stands for progress;
Fflush (stdout): To refresh the contents of the row buffer;
Usleep (100000): Sleep time, that is, the speed of control progress;
The results of the operation are as follows:
Today's buffer is first mentioned here ~ ~
Welcome to put forward valuable comments oh.