vc读取文本文件

本文介绍了在VC中处理文本文件的方法,包括使用CStdioFile和CFile类的读写操作,强调了CFile的Read和Write函数,并提醒注意行结束符和文件定位。示例代码展示了如何读取文件、更新行内容并写回文件。
摘要由CSDN通过智能技术生成

CString   csLine;  
  try  
  {  
        CStdioFile   file("c://autoexec.bat",CFile::modeRead);  
        while(file.ReadString(csLine))  
              AfxMessageBox(csLine);  
  }  
  catch(...)  
  {  
            AfxMessageBox("打开文件错");  
  }  
参考一段代码:使用ifstream  
  char*   pszPath   =   NULL;  
  ::GetMacroBasePath(&pszPath);  
  ifstream   file;  
  file.open(pszPath,ios::nocreate|ios::in);  
  if(pszPath)   delete   pszPath;  
  if(!file.good())   return   rtnValue;  
   
  char   buffer[256];  
  file.getline(buffer,255);  
  if(_stricmp(buffer,"VERSION   =   1.0")   !=   0)  
  return   rtnValue;  
   
  CString   strTemp(_T(""));  
  file.getline(buffer,255);  
  while(_stricmp(buffer,"")   !=   0)  
  {  
  strTemp   =   CString(buffer);  
                                      。。。  
                                      file.getline(buffer,255);  
                      }  
CStdioFile   f;  
  CFileException   e;  
  char   *FileName   =   "temp.txt";  
  if(   !f.Open(   FileName,   CFile::modeRead,   &e   )   )  
  {   return;}  
  CString   line;  
  while   (f.ReadString(line))  
  {  
  }  
  f.Close();
char   szT[256];  
  memset(   szT,   0,   256   );  
  fp   =   fopen(   "test.txt",   "r"   );  
   
  fscanf(   fp,   "%s",   szT   );  
  strcpy(   szcc,   szT   );  
  while(   !feof( 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值