CFile 深入研究之 CFile::modeNoTruncate

原文:CFile 深入研究之 CFile::modeNoTruncate

即时通讯爱好者 NanShan 最近专注于研究 CFile 的各种问题,今天主要是 CFile::modeNoTruncate 相信研究。

CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.


  1. //读取注册文件。
  2.     CString username;
  3.     CFile file;
  4.     file.Open(_T("user.dat"), CFile::modeRead|CFile::modeCreate|CFile::modeNoTruncate, NULL);//保留源文件内容。
  5.     if (file.GetLength() == 0)
  6.     {
  7.         
  8.         GetDlgItem(IDC_ENTER)->EnableWindow(FALSE);
  9.         GetDlgItem(IDC_REGISTER)->EnableWindow(TRUE);
  10.         MessageBox("您还没有注册,请点击注册按钮进行注册。");
  11.     }
  12.     else
  13.     {
  14.         GetDlgItem(IDC_ENTER)->EnableWindow(TRUE);
  15.         GetDlgItem(IDC_REGISTER)->EnableWindow(FALSE);
  16.     }
  17.     file.Close();
复制代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值