BOOL CRwFile::WriteToFile(int m,CStringArray &str)
{
CStdioFile sf;
sf.Open("mylist.txt",CFile::modeWrite | CFile::modeCreate);
CString st=sf.GetFileName();
SetFileAttributes(sf.GetFileName(),FILE_ATTRIBUTE_HIDDEN);
if(m)
{
count=m;
sf.Write(&count,sizeof(int));
m=0;
while(m<count)
{
sf.WriteString(str[m]);
sf.Write(&ch,sizeof(char));
m++;
}
sf.Close();
return TRUE;
}
sf.Close();
return TRUE;}
为什么设置文件隐藏属性,写文件就现错误,去掉这句代码,写文件就正常..

解决方案 »

  1.   

    那CFile不能读取隐藏的文件吗?
      

  2.   

    你试试CreateFilehttp://www.bccn.net/Article/kfyy/vc/jszl/200608/4359.html
      

  3.   

    CFile不支持创建文件就隐藏
    CreateFile可以
      

  4.   

    CStdioFile sf;
    VERIFY(sf.Open("F:\\11.txt",CFile::modeWrite | CFile::modeCreate));
    CString st=sf.GetFilePath();
    BOOL bRet = SetFileAttributes(st,FILE_ATTRIBUTE_HIDDEN);
    if(bRet)
    {
    sf.WriteString(_T("Hello,World!"));
    }

    sf.Close();
    VC6下,这样写没有问题~
      

  5.   

    要注意的是运行第二次的时候,CFile.Open();失败的,错误是拒绝访问GetLastError为5