vc中的文件操作
File Operations in VC
1:Find the file
CString strFileName;
CFileFind finder;
BOOL bWorking=finder.FindFile(”c:\windows\*.cab”);
if(bWorking)
{
bWorking=finder.FindNextFile();
strFileName=finder.GetFileName();//or finder.GetFileTitle();
}
2:Open or Save file
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,”All Files(*.*)|*.*||”
,AfxGetMainWnd());
3:Read and Write File
//Read File
char cRead[10]; CFile mFile(_T(”test.txt”),CFile::modeRead);
if(mFile.GetLength()<2)
return ;
mFile.Read(cRead,10);
mFile.Close();
//Write File:
CFile mFile(_T(”test.txt”),CFile::modeWrite|CFile:modeCreate);
File Operations in VC
1:Find the file
CString strFileName;
CFileFind finder;
BOOL bWorking=finder.FindFile(”c:\windows\*.cab”);
if(bWorking)
{
bWorking=finder.FindNextFile();
strFileName=finder.GetFileName();//or finder.GetFileTitle();
}
2:Open or Save file
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,”All Files(*.*)|*.*||”
,AfxGetMainWnd());
3:Read and Write File
//Read File
char cRead[10]; CFile mFile(_T(”test.txt”),CFile::modeRead);
if(mFile.GetLength()<2)
return ;
mFile.Read(cRead,10);
mFile.Close();
//Write File:
CFile mFile(_T(”test.txt”),CFile::modeWrite|CFile:modeCreate);