文件不能打开!!!

striveforit 2009-08-13 11:25:44
想了半天都不明白。。崩溃了。。
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);
}
...全文
94 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxm378728535 2009-08-13
  • 打赏
  • 举报
回复
我也遇到过这样的问题
striveforit 2009-08-13
  • 打赏
  • 举报
回复
执行完 ofstream ofs(fn1,ios::out|ios::binary);
能在根目录自动生成File.dat
执行完 fstream ifs(fn2,ios::in|ios::binary);
却没有反应,反而输出File.idx不能打开,是怎么回事呢?

65,206

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧