what is the flush() function defined in fstream.h?
what is the flush() function defined in fstream.h?
C++ Makes you Feel Better
"Gravity connot be held reponsible for people falling in love"--Albert Einstein
It makes sure that any data which is still in a buffer between your program and the actual file is actually written to that file.
PS
They're called manual pages
yeah, i was wondering that question, can you xplain it a little better?
"Buffering", as you may already be aware, stores data in an array until one of two conditions occur. (Oversimplifying here, but it'll give you a "leg up" on what's taking place.)
The first condition is an "overflow" of the buffer (array) which signals the compiler to "write" the contents of the buffer to the appropriate file. Simply put, the buffer is full and it's time to empty it.
The second condition (the subject of this thread) is when the buffer is "flushed". This 'forces' the writing of the buffer contents to the appropriate file, typically, before the buffer is full.
A trivial, but perhaps enlightening, example of implicit flushing is the "tie" between cout and cin.
Since the output stream is buffered, unless it were "flushed", the user wouldn't see the prompt, i.e. the buffer would hold our prompt message until the buffer was full.Code:std::cout << "Enter your age: "; std::cin >> age;
However, due to the tie between 'ostream' and 'istream', there is an implicit call, cout.flush(), that forces the message to be displayed before extracting data to the input stream.
Buffering is actually a far more complicated topic than what I've attempted to give you here, but I hope this helps a little.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow