
菜问题:怎么判断文件CFile已打开?
展开全部
在打开文件时可通过检查 Open() 函数的返回值,非零即打开成功。
如:CFile file;
if(file.Open("d:\t.txt",CFile::modeRead))
AfxMessageBox("Succeed to open the file!");elseAfxMessageBox("Error when opening the file!");
如果要在关闭前判断,可以用一个间接的办法(尽管这个办法不够好),如:
CFileStatus fs;
if(file.GetStatus(fs))
file.Close();
用前一位的方法要好一点!
GetStatus(_T(strFilename),status))返回值是 BOOL 型的,即 TRUE 或 FALSE .
如:CFile file;
if(file.Open("d:\t.txt",CFile::modeRead))
AfxMessageBox("Succeed to open the file!");elseAfxMessageBox("Error when opening the file!");
如果要在关闭前判断,可以用一个间接的办法(尽管这个办法不够好),如:
CFileStatus fs;
if(file.GetStatus(fs))
file.Close();
用前一位的方法要好一点!
GetStatus(_T(strFilename),status))返回值是 BOOL 型的,即 TRUE 或 FALSE .
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询