文件不能打开!!!

striveforit striveforit 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
想了半天都不明白。。崩溃了。。
build没问题,就是执行的时候,在IFInsert()那一步File.idx不能打开
char *p1=".\\File.dat",*p2=".\\File.idx";Append()中的ofstream ofs(fn1,ios::out|ios::binary);就没问题
而IFInsert()就出问题呢???

template<class T,class T1>
void File<T,T1>::Append(char*fn1,char*fn2,T1 e)
{
ofstream ofs(fn1,ios::out|ios::binary);
if(!ofs){cout<<fn1<<"不能打开"<<endl;exit(1);}
ofs.seekp(0,ios::end);
int flen=ofs.tellp()/b1; //当前文件个数
ofs.write((char*)& e,sizeof(e));
ofs.close();
T x;
strcpy(x.key,e.key);
x.length=0;
x.location=0;
IFInsert(fn2,x);
cout<<"添加记录完成\n";
}
template<class T,class T1>
void File<T,T1>::IFInsert(char*fn2,T x)
{
fstream ifs(fn2,ios::in|ios::binary);
if(!ifs){cout<<fn2<<"不能打开"<<endl;exit(1);}
……
}

void main()
{ char *p1=".\\File.dat",*p2=".\\File.idx";
……
File<IndexItem,ElemType>myfile;
myfile.Append(p1,p2,e);
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
striveforit
C++ 语言 65,214 成员 250,514 内容