| for ostream | ostream& flush (ostream& os); |
|---|---|
| basic template | template <class charT, class traits>basic_ostream<charT,traits>& flush (basic_ostream<charT,traits>& os); |
<<) operations on output streams (see example below).| flag | error |
|---|---|
| eofbit | - |
| failbit | May be set if the construction of a sentry object failed. |
| badbit | The synchronization operation failed (including if the function catches an exception thrown by an internal operation). When set, the integrity of the stream may have been affected. |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Flushing files (flush manipulator)
#include <ostream> // std::flush
#include <fstream> // std::ofstream
int main () {
std::ofstream outfile ("test.txt");
for (int n=0; n<100; n++)
outfile << n << std::flush;
outfile.close();
return 0;
}
test.txt to be flushed 100 times.