有关"fstream"问题
cyniq 2000-07-25 12:29:00 我想在很多文件的末尾添加"end",代码如下:
void CZhDoc::AddEnd()
{
CString sdir="";
ofstream file;
for(int i=0;i<10;i++)
{
for(int j=0;j<N;j++)
{
sdir="d:\\" + dir[i] + "\\" + sName[j] +
direct[i] + ".DAT";
file.open(sdir,ios::nocreate and ios::app and ios::out);
file<<"end"<<endl;
file.close();
}
}
}
其中,有些文件可能不存在,不存在的文件不加。
上面代码的问题是:当有不存在的文件时,会影响其后面打开的已存在文件,使之不加"end".请教各位其原因或解决方法。