When to flush the buffer

  ~logoutbuf()
  {
    sync();
  }
The buffer should also be flushed just prior to the stream buffer being destroyed. Therefore sync should also be called from the destructor.