Fstream文件正在被重写
fstream file being rewritten
我正在编写一个输出文本文件的程序。任何时候我想写入文件,我打开它,seekp()
到文件的末尾,写入它,然后关闭它。然而,似乎每次执行新的写操作时,它都会替换文件中先前存在的所有数据。
output.open("output.txt", fstream::out);
output.seekp(0, ios::end);
output << "Record " << key << " does not exist.r";
output.close();
这是正确的方式追加每写到文件的末尾吗?如果您有任何可能导致整个文件被重写的想法,我将不胜感激。
添加fstream::app
标志
output.open("output.txt", fstream::out | fstream::app);
fstream::out
总是覆盖文件中的数据。要追加内容,请使用模块fstream::app
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- .cpp和.h文件中的模板专用化声明
- MFC:重写附属 DLL 中 RC 文件中的位图路径
- 如何在不重写整个视频文件的情况下仅替换流中的一个数据框架?(ffmpeg)
- 用 0 重写文件。我做错了什么?
- 在C 中重写文本文件
- 如何用参数重写构造函数并在单独的文件中实现它
- 从txt文件中读取数字,添加一些数字,然后在c ++中将其重写为其他文件
- C++重写文件
- 重写文件中的数据,而不关闭文件并重新打开它.(c++)
- 重写部分二进制文件
- 如何使用 C++ 在.txt文件中写入、读取和重写
- OpenCV 重写压缩的视频文件
- 添加和删除文件片段以不完全重写它的最有效方法是什么
- 重写c库文件函数
- 重写与添加到c++中已读csv文件的末尾
- 重写文件内容上的按钮点击在qt
- 删除文件的开头,而不重写整个文件
- Fstream文件正在被重写
- 如何重写/覆盖文本文件中的字符串/行