本文介绍了我可以隐式刷新数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种隐式刷新数据到输出流的方法?
Is there a way to implicitly flush data to an output stream?
#include <iostream> #include <fstream> using namespace std; #define log logstream int main() { ofstream logstream("test.log"); log << "Test1" << 123 << endl; // explicitly flushed log << "Test2" << 123; // ? // Test2 not written, yet... cout << "Check log file..." << endl; int tmp; cin >> tmp; }我希望能够在不每次指定<< endl操纵器的情况下登录.
I would like to be able to log without specifying the << endl manipulator every time.
推荐答案您可以使用 std::unitbuf .
You may use std::unitbuf.
log << std::unitbuf;然后在每次插入时进行刷新.
And then flush would be done at each insertion.
更多推荐
我可以隐式刷新数据吗?
发布评论