FreeBSD Manual Pages
std::basic_ostream::flush(3) C++ Standard Libary std::basic_ostream::flush(3) NAME std::basic_ostream::flush - std::basic_ostream::flush Synopsis basic_ostream& flush(); Writes uncommitted changes to the underlying output sequence. Be- haves as an UnformattedOutputFunction. If rdbuf() is a null pointer, the sentry object is not constructed. Otherwise, after constructing and checking the sentry object, calls rdbuf()->pubsync(). If the call returns -1, calls setstate(badbit). Parameters (none) Return value *this Exceptions May throw std::ios_base::failure if (exceptions() & badbit) != 0. Example // Run this code #include <chrono> #include <iostream> #include <thread> using namespace std::chrono_literals; void f() { std::cout << "Output from thread... "; for (int i{1}; i != 10; ++i) { std::this_thread::sleep_for(250ms); std::cout << i << ' '; // output three numbers at once; // the effect is observable only in real-time if (0 == (i % 3)) std::cout.flush(); } std::cout << std::endl; // flushes as well } int main() { std::thread tr{f}; std::this_thread::sleep_for(150ms); std::clog << "Output from main\n"; tr.join(); } Output: Output from main Output from thread... 1 2 3 4 5 6 7 8 9 Defect reports The following behavior-changing defect reports were applied retroac- tively to previously published C++ standards. DR Applied to Behavior as published Cor- rect behavior flush() did not behave as an LWG 581 C++98 UnformattedOutputFunction behaves as an because of the resolution of LWG issue Unformat- tedOutputFunction 60 See also pubsync invokes sync() (public member function of std::basic_stream- buf<CharT,Traits>) sync synchronizes the buffers with the associated character se- quence [virtual] (virtual protected member function of std::basic_stream- buf<CharT,Traits>) flush flushes the output stream (function template) endl outputs '\n' and flushes the output stream (function template) sync synchronizes with the underlying storage device (public member function of std::ba- sic_istream<CharT,Traits>) http://cppreference.com 2024.06.10 std::basic_ostream::flush(3)
NAME | Synopsis | Parameters | Return value | Exceptions | Example | Output: | See also
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::ostream::flush&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>
