CFILE的使用:读文件

来源:互联网 发布:mac brew gradle home 编辑:程序博客网 时间:2024/06/09 21:33

逐行

/*
  CStdioFile   sfile; 
  if(!sfile.Open(dlg2.m_szFilepath,CFile::modeRead)) 
  { 
   AfxMessageBox("Open   file   error!"); 
   return; 
  } 
  CString strText="" ;
  CString szLine ;
    
  while( sfile.ReadString( szLine ) )
  {
   strText += szLine + "/r/n";
  }
  m_editFileContent.SetWindowText(strText);
  sfile.Close();
  */

显示,不断行


  CFile   file; 
  if(!file.Open(dlg2.m_szFilepath,CFile::modeRead)) 
  { 
   MessageBox("Open   file   error!"); 
   return; 
  } 
  //CString  strLine;
  char *pbuf;
  
  pbuf   =   new   char[file.GetLength()+10]; 
        memset(pbuf,'/0',file.GetLength()+1);  
        UINT nBytesRead = file.Read(pbuf, file.GetLength());
  
  m_editFileContent.SetWindowText(pbuf);
  file.Close();
  delete [] pbuf;
 }