如何使用fstream附加到文件fstream :: app标志似乎不起作用 [英] How to append to a file with fstream fstream::app flag seems not to work

查看:68
本文介绍了如何使用fstream附加到文件fstream :: app标志似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想写(附加)到日志文件。我在这里查看:

http://www.cplusplus .com / reference / iostream / fstream / open /

i simply want to write (append) to a logfile. I looked it up here:
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();


推荐答案

fstream :: app | fstream :: out 而不是 fstream :: app 。如果不指定 out app 就没有任何意义(有人可能认为它应该暗示了 out ,但不是)。

fstream::app|fstream::out instead of fstream::app. app doesn't make sense without specifying out (one could think it should have implied out, but it doesn't).

这篇关于如何使用fstream附加到文件fstream :: app标志似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆