gpt4 book ai didi

c++ - 如何使用 fstream fstream::app 标志附加到文件似乎不起作用

转载 作者:IT老高 更新时间:2023-10-28 22:01:57 26 4
gpt4 key购买 nike

我只是想写(追加)到一个日志文件。我在这里查了一下:
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::appapp 没有指定 out 就没有意义(人们可能认为它应该隐含 out,但事实并非如此)。

关于c++ - 如何使用 fstream fstream::app 标志附加到文件似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4712192/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com