无法在c++中使用追加模式在文件中插入数据
Not able to insert data in file using append mode in c++
我的代码是:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream file;
file.open("abc.txt",ios::app);
file<<"hello";
file.close();
return 0;
}
上面的代码正在创建一个空文件。
谁能指出我错在哪里
打开文件时,除了指定追加(ios::app
)外,还必须指定要输出到文件(ios::out
)。您可以将它们与位或(|
)组合,因为它们表示单位标志。
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream file;
file.open("abc.txt",ios::app | ios::out);
file << "hello";
file.close();
return 0;
}
相关文章:
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- C++ 使用存储在动态数组中的文本文件中的数据查找模式
- 文件模式标志"ios::app"是否用于删除文件(如果文件已存在)?
- C++二进制模式下写入和读取文件
- C++将特定的数据模式从RFID阅读器写入文本文件
- glob只给出匹配模式的第一个文件
- 在 eclipse 中以发布模式构建后没有可执行文件
- 是否有标准的文件保存和交换模式
- 生成文件匹配规则和配方中的模式
- ios::app 和 ios::noreplace 模式在文件处理中有什么区别?
- C++文件可配置的编译时多态模式?
- QTextStream 无法使用开放模式写入文件,包括"t" QIODevice::Append
- Gettin 目标模式不包含来自未修改的生成文件的"%"?
- 为什么隐藏文件无法在 MFC 中的创建和写入模式下打开?
- 如何仅使用 std::filebuf 将数据(二进制模式)写入文件
- Visual Studio在发布模式下构建,但用户收到消息说他们需要调试文件
- 具有混合依赖项的生成文件模式规则
- 文件模式在turbo c++中不工作
- 生成文件模式规则:循环生成文件.o < - 删除生成文件依赖项
- 生成文件模式规则差异