文件读入:
CFileDialog fileDlg(TRUE, "rtf", NULL, OFN_FILEMUSTEXIST,"rtf files(*.rtf)|*.rtf|");
// display the file dialog
// if I press the Cancel button
if (fileDlg.DoModal () == IDCANCEL)
{
}
// I obtain the file name
CString filename = fileDlg.GetPathName ();
m_strFilename=fileDlg.GetFileName();
CFile fis;
fis.Open(filename, CFile::modeRead | CFile::shareExclusive);
m_rtf.SetRtf(&fis);
// on the title bar will appear the document name which is opened
// lines added on Wednesday 26 September 2001
CString msg;
msg.Format("MyRtf - %s" , filename );
SetWindowText ( msg ) ;
fis.Close();
===============================================
读入文件保存在Cstring中:
Cstring strFile;
int nFileLength = fis.getLength();
fis.read(strFile.getBuffer(nFileLength),nFileLength);
fis.ReleaseBuffer();
================================================
//
================================================
文件读出:
if (fileDlg.DoModal () == IDCANCEL)
{
}
// I obtain the file name
CString filename = fileDlg.GetPathName ();
m_strFilename=filename;
CFile fis;
// I open the file with tne modeWrite and modeCreate mode
fis.Open(filename, CFile::modeCreate | CFile::modeWrite);
// I put the content in the file
fis.Close();
=================================================
将Cstring中的内容保存在Cfile中:
Cstring strFile;
int nFileLength = strFile.getLength();
strFile.write(strFile,strFile.getLength());