The flush manipulator function is used to completely vacant the output stream. This function takes in no arguments or parameters. This function is not that of a much significance when normal output is printed on the output console. But when output is used for different reasons where it is very important to clear the output stream buffer, like in case of file handling where the output buffer has to be cleared repeatedly, it can be used. flush function does not alter input stream.
Code:
// using flush function
#include<iostream>#include<iomanip>usingnamespacestd;
intmain(){
cout<<"My name is Abhinav Verma \n";
cout.flush(); //flushes the output streamcout<<"I am typing \n";
cout.flush();
return0;
}
The screenshot showing the flush function is shown below:
Comments