64,636
社区成员
发帖
与我相关
我的任务
分享
ofstream outfile("c:\\11\\22\\33\33\\data.txt",ios::app|ios::binary);
if (!outfile) //!运算符重载
{
return 0;
}
const char* p_str = "this is test";
int aa=0x1234;
outfile.write((char*)&aa,sizeof(aa));
aa=0x5678;
outfile.write((char*)&aa,sizeof(aa));
outfile.close();
bool init()
{
static bool has_init = false;
if (has_init)
{
return(true);
}
if (!has-init-data-in-file)
{
add-init-data-in-file;
}
has_init = true;
return(true);
}
如果考虑多线程的问题,可能还需要让它在main之前执行,(放到一个全局对象、单例的构造中)if (!outfile)
这个好像是不靠谱的
我现在都用
if (!outfile.is_open())
代替