如何使用 fstream fstream::app 标志附加到文件似乎不起作用
我只是想写入(附加)到日志文件。我在这里查了一下:
http://www.cplusplus.com/reference/iostream/fstream/open/
这就是我所做的
#include <fstream>
fstream outfile;
//outfile.open("/tmp/debug.txt" ); // works, simply for writing
outfile.open("/tmp/debug.txt", fstream::app ); // does nothing
outfile << "START" << endl;
outfile.close();
i simply want to write (append) to a logfile. I looked it up here:
http://www.cplusplus.com/reference/iostream/fstream/open/
so this is what i did
#include <fstream>
fstream outfile;
//outfile.open("/tmp/debug.txt" ); // works, simply for writing
outfile.open("/tmp/debug.txt", fstream::app ); // does nothing
outfile << "START" << endl;
outfile.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fstream::app|fstream::out
而不是fstream::app
。如果不指定out
,app
就没有意义(人们可能认为它应该隐含out
,但事实并非如此)。fstream::app|fstream::out
instead offstream::app
.app
doesn't make sense without specifyingout
(one could think it should have impliedout
, but it doesn't).