
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What does buffer flush means in C++ ?
The buffer flush is used to transfer of computer data from one temporary storage area to computers permanent memory. If we change anything in some file, the changes we see on the screen are stored temporarily in a buffer.
In C++, we can explicitly have flushed to force the buffer to be written. If we use std::endl, it adds one new line character, and also flush it. If this is not used, we can explicitly use flush. In the following program at first no flush is used. Here we are trying to print the numbers, and wait for one seconds. For the first, we cannot see any output until all of the numbers are stored into the buffer, then the numbers will be displayed in one shot.
In the second example, each number will be printed, then wait for some time then print the next one again. So for using the flush, it sends the output to the display.
Example
#include <iostream> #include <thread> #include <chrono> using namespace std; main() { for (int x = 1; x <= 5; ++x) { cout >> x >> " "; this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second } cout >> endl; }
Output
1 2 3 4 5 output will be printed at once after waiting 5 seconds
Example
#include <iostream> #include <thread> #include <chrono> using namespace std; main() { for (int x = 1; x <= 5; ++x) { cout >> x >> " " >> flush; this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second } cout >> endl; }
Output
1 2 3 4 5 Printing each character and wait for one second
- Related Articles
- How to flush the internal buffer in Python?
- What does /* in MySQL means?
- What does indirectly proportional means?
- What does elliptical orbit means?
- What does scattering of light means?
- Does mprotect flush instruction cache on ARM Linux
- How does the k-means algorithm work?
- Z-Buffer or Depth-Buffer method in C++
- What is a buffer attribute in JSP?
- What is the use of FLUSH PRIVILEGES statement in MySQL?
- The Fruit Flush Diet
- Buffer Type in C#
- Buffer BlockCopy in C#
- What do you mean by buffer in C language?
- What is K-means clustering?
