文件模式在turbo c++中不工作

File modes are not working in turbo c++

本文关键字:工作 c++ turbo 模式 文件      更新时间:2023-10-16

我尝试使用文件模式,如ios::app和ios::ate不工作。每次写入二进制文件时,内容都会被新的内容所替换。我甚至尝试使用seekp(ios::end)而不是追加模式,它仍然不添加内容,而只是替换它。这是我输入的代码:

#include<fstream.h>
 //included other required header files
   struct test 
   {char que[100];
   char ans[20];
    };
  int main()
{
test s ;
ofstream out("test.dat",ios::binary||ios::app);
strcpy(s.que,"abcd");
strcpy(s.ans,"agg");
out.write((char*)&s,sizeof(s));
return 0;
}
我不知道出了什么事。我想知道这是不是因为turbo c++是一个旧的编译器?如果是这样,我如何将内容附加到文件的末尾?

替换为

ios::binary||ios::app
与这个:

ios::binary | ios::app

要组合的操作使用|(位or)绑定在一起,而不是使用||(逻辑or)。