代码如下:CFile f;
CFileException e;
if(!f.Open("E:\\mm.txt",CFile::modeCreate,&e))
{
TCHAR szError[1024];
e.GetErrorMessage(szError, 1024);
cout << "Couldn't open source file: ";
cout << szError<<endl;
return 1;
}
f.Close();
SetFileAttributes("E:\\mm.txt",FILE_ATTRIBUTE_HIDDEN);
if(!f.Open("E:\\mm.txt",CFile::modeReadWrite,&e))
{
TCHAR szError[1024];
e.GetErrorMessage(szError, 1024);
cout << szError<<endl;
return 1;
}
f.Close();
错误提示:
Couldn't open source file: 对 E:\mm.txt 的存取被拒绝。
Press any key to continue

解决方案 »

  1.   

    f.Open("E:\\mm.txt",CFile::modeCreate|CFile::modeWrite,&e)
      

  2.   

    msdn转了吗??
    没装的话 装个吧  编程的没有这个可不行CFile类的 open函数 解释里面 最下面有一个 note
    Note  
    Under Windows NT, if the file lpszFileName exists and is hidden, and if nOpenFlags includes CFile::modeCreate but is not OR-ed with CFile::modeNoTruncate, Open fails. Under Windows 95/98 and later, the call succeeds and creates a new file that is not hidden.不知道你的英文怎么样  自己看看吧 
      

  3.   

    MSDN上这样讲:
    FILE_ATTRIBUTE_HIDDEN 
    The file is hidden. It is not included in an ordinary directory listing. 
    莫非open打开的是ordinary directory?
      

  4.   

    谢谢,用了CFile::modeNoTruncate就可以打开了,看来认真阅读MSAN还是很重要的。