diff --git a/include/dmlc/io.h b/include/dmlc/io.h index 875fab330..e34d02201 100644 --- a/include/dmlc/io.h +++ b/include/dmlc/io.h @@ -150,6 +150,10 @@ class ostream : public std::basic_ostream { : basic_ostream(NULL), buf_(buffer_size) { this->set_stream(stream); } + // explictly synchronize the buffer + virtual ~ostream() { + buf_.pubsync(); + } /*! * \brief set internal stream to be stream, reset states * \param stream new stream as output @@ -209,6 +213,7 @@ class istream : public std::basic_istream { : basic_istream(NULL), buf_(buffer_size) { this->set_stream(stream); } + virtual ~istream() {} /*! * \brief set internal stream to be stream, reset states * \param stream new stream as output @@ -281,6 +286,7 @@ inline bool Stream::Read(std::string *out_str) { // implementations for ostream inline void ostream::OutBuf::set_stream(Stream *stream) { + if (stream_ != NULL) this->pubsync(); this->stream_ = stream; this->setp(&buffer_[0], &buffer_[0] + buffer_.size() - 1); }