VC++ implementation of CStdioFile to write and read files and automatic line wrapping method

  • 2020-04-02 02:32:25
  • OfStack

CStdioFile described in this paper can be implemented in VC++ mainly used to write and read the file function, inherited from the CFile class, it will automatically process "\r\n", encountered "\n" automatically add \r and set the cursor in the current line, it can also automatic line wrapping, but the use of CStdioFile in the processing of large file speed is a bit slow,

CStdioFile is used to write the following code to read the file:


LPTSTR filter=_T("Playlist Files(.txt)|*.txt|");
CString tempPath;
CFileDialog saveFileDlg(FALSE,NULL,NULL,OFN_PATHMUSTEXIST,filter,NULL,0,TRUE);
saveFileDlg.m_ofn.lpstrInitialDir=_T("E:\media"); //Set default directory
if(saveFileDlg.DoModal()==IDOK)
{
tempPath=saveFileDlg.GetPathName();
}
CStdioFile listfile;
tempPath+=_T(".txt");//Definition read TXT text file
listfile.Open(tempPath,CFile::modeCreate|CFile::modeReadWrite|CFile::typeText);
for (int i=0;i<m_ctrlPlayList.GetCount();i++)
{
CString temp;
m_ctrlPlayList.GetText(i,temp);
temp+="n";
listfile.WriteString(temp);
}

It is hoped that the example described in this paper can be used for reference and help in VC++ project development.


Related articles: