Support flushing output streams

This commit is contained in:
Nikita Lisitsa 2021-07-01 20:12:48 +03:00
parent a56cdcfc73
commit 82e7164670
3 changed files with 9 additions and 0 deletions

View file

@ -83,6 +83,8 @@ namespace psemek::io
std::size_t write(char const * p, std::size_t size) override; std::size_t write(char const * p, std::size_t size) override;
void flush() override;
~file_ostream() override ~file_ostream() override
{ {
reset(); reset();

View file

@ -18,6 +18,7 @@ namespace psemek::io
struct ostream struct ostream
{ {
virtual std::size_t write(char const * p, std::size_t size) = 0; virtual std::size_t write(char const * p, std::size_t size) = 0;
virtual void flush() {}
virtual ~ostream() {} virtual ~ostream() {}
}; };

View file

@ -63,4 +63,10 @@ namespace psemek::io
return std::fwrite(p, 1, size, file_); return std::fwrite(p, 1, size, file_);
} }
void file_ostream::flush()
{
if (!file_) throw null_ostream{};
std::fflush(file_);
}
} }