GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_ostream::flush(3) C++ Standard Libary std::basic_ostream::flush(3)

std::basic_ostream::flush - std::basic_ostream::flush


basic_ostream& flush();


Writes uncommitted changes to the underlying output sequence.


If rdbuf() is a null pointer, does nothing


Otherwise, behaves as an UnformattedOutputFunction (since C++11). After constructing
and checking the sentry object, calls rdbuf()->pubsync(). If the call returns -1,
calls setstate(badbit).


(none)


*this


May throw std::ios_base::failure if (exceptions() & badbit) != 0.

// Run this code


#include <thread>
#include <iostream>
#include <chrono>
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 from main
Output from thread... 1 2 3 4 5 6 7 8 9


pubsync invokes sync()
(public member function of std::basic_streambuf<CharT,Traits>)
sync synchronizes the buffers with the associated character sequence
[virtual] (virtual protected member function of std::basic_streambuf<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::basic_istream<CharT,Traits>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.