【发布时间】:2014-07-04 12:04:48
【问题描述】:
我想知道是否可以从 std::ostream 继承,并以将一些信息(例如行号)添加到每行开头的方式覆盖 flush()。然后我想通过 rdbuf() 将它附加到 std::ofstream (或 cout),这样我就得到了这样的东西:
ofstream fout("file.txt");
myostream os;
os.rdbuf(fout.rdbuf());
os << "this is the first line.\n";
os << "this is the second line.\n";
将其放入 file.txt
1 this is the first line.
2 this is the second line.
【问题讨论】: