回答
std::ofstream
文件不直接支持此操作。如果这是一个重要的要求,你可以做什么是创建一个过滤流缓冲区,它在内部使用std::filebuf
,但也记录是否有任何输出完成。这可能看起来看起来像这样简单:
struct statusbuf:
std::streambuf {
statusbuf(std::streambuf* buf): buf_(buf), had_output_(false) {}
bool had_output() const { return this->had_output_; }
private:
int overflow(int c) {
if (!traits_type::eq_int_type(c, traits_type::eof())) {
this->had_output_ = true;
}
return this->buf_->overflow(c);
}
std::streambuf* buf_;
bool had_output_;
};
可以初始化与此一std::ostream
并根据需要查询流缓冲区:
std::ofstream out("some file");
statusbuf buf(out.rdbuf());
std::ostream sout(&buf);
std::cout << "had_output: " << buf.had_output() << "\n";
sout << "Hello, world!\n";
std::cout << "had_ouptut: " << buf.had_output() << "\n";
您可以使用ofstream.rdbuff来获取文件缓冲区,并使用streambuf::sgetn来读取它。我相信这应该工作。
不,它不会工作:当前正在写入的流缓冲区的读取缓冲区通常不会被填充。这两个缓冲区没有任何关系,并且它们不会保持同步。 – 2012-02-09 06:31:28
我现在要试试这个 – WeaselFox 2012-02-09 06:37:07
当然,给它一个。但是,即使存在标准库实现,甚至是大部分实现它的实现,确定其工作原理的方式也是读取标准。我很确定标准不能保证这一点,我所做的实现当然不会保持两个缓冲区同步。 – 2012-02-09 06:40:12
- 1. 检查dataGridView是否为空
- 2. 检查JValue是否为空
- 3. 检查imageView是否为空
- 4. 检查tabControl1是否为空?
- 5. 检查CSV是否为空
- 6. 检查double是否为空
- 7. 检查列是否为空
- 8. 检查ALAssetsLibrary是否为空
- 9. 检查ArrayCollection是否为空
- 10. laravel检查是否为空
- 11. 检查textarea是否为空
- 12. 检查NumericUpDown是否为空
- 13. 检查ImageSource是否为空
- 14. 检查是否为空JasperReports
- 15. 检查是否为空JFormattedTextField
- 16. 检查editText是否为空
- 17. 检查JTextField是否为空
- 18. 检查是否为空VB.NET
- 19. 检查StringBuffer是否为空
- 20. 检查OnAction是否为空
- 21. 检查NSDictionary是否为空
- 22. 检查JTextFields是否为空
- 23. 检查managedobjectcontext是否为空?
- 24. 检查它是否为空
- 25. 检查stderr是否为空
- 26. 检查NSRect是否为空
- 27. 检查DataView是否为空
- 28. 检查是否为空DataRow
- 29. 检查EditText是否为空
- 30. 检查TextView是否为空?
广东话你EOF或rdstate功能检查呢? – sarat 2012-02-09 06:29:34