MFC中简单的文件操作writeString,readString

在初次使用mfc的文件操作时总是会犯很多小错误.本人总结了点,下面就是我所写的一段源代码.

注意:typeBinary可以输入中文,回车使用"/r/n",

CString CmytestApp::GetStartPath()
{
 CString szExeFile;
 ::GetModuleFileName(NULL,szExeFile.GetBuffer(MAX_PATH),MAX_PATH);
 szExeFile.ReleaseBuffer(MAX_PATH);

 return szExeFile.Left(szExeFile.ReverseFind(_T('//'))+1);
}


void CmytestApp::SavePhoto()

 CStdioFile myfile;
 CFileException fileException;

 CString szFile=(LPCTSTR)(theApp.GetStartPath()+_T("config.txt"));//获得当前应用程序的位置

 CString strOrder;
 BYTE a=(BYTE)2;
 strOrder.Format(_T("年ok 看看看月/r/n"));
 
// if(myfile.Open(szFile,CFile::typeText|CFile::modeCreate|CFile::modeReadWrite,&fileException))  //重写的方式
 if(myfile.Open(szFile,CFile::typeBinary|CFile::modeReadWrite|CFile::modeNoTruncate,&fileException)) //追加的方式
 {//typeBinary
   CString aa;
  while(myfile.ReadString(aa))
  {
   
  }
  myfile.SeekToEnd();
 
  
  
  myfile.WriteString(_T("dd /r/n"));
  myfile.WriteString(strOrder);
  
 
 }
 if(&myfile)
  myfile.Close();
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值