Flushing the buffer

virtual int sync()
  if(!buffer_.empty() && out_)
  {
    out_->sputn(&buffer_[0],
      static_cast<std::streamsize>(buffer_.size()));
    buffer_.clear();
  }
  return 0;
}
When basic_ostream::flush is called, either directly or via std::endl, it starts a chain of function calls that finally results in basic_streambuf::sync being called.

The sync function is used to flush the buffer to the output stream. Before an attempt is made to flush the buffer, it is checked to make sure it is not empty, along with the validity of the output stream pointer.

As the elements of a vector are guaranteed, by the standard, to be contiguous, the entire buffer can be passed to the output stream via a single call to its sputn function, which takes a pointer to the first element and the number of elements as its arguments.

The buffer is then cleared.