1.在循环使用数组时需要清理数组

  CString str;

  memset(str,0,strlen(str));

判断两个字符串包含数字大小是否相等

  CString str="22";

  if(str!="22"){}

2.读取文件

//2.读人员文件renyuan.txt
HANDLE rFile;
DWORD dwRet;
memset(str,,);
rFile = CreateFile(_T("\\NANDFlash\\renyuan.txt"),GENERIC_READ ,,NULL,OPEN_EXISTING,,NULL);
if(rFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("打开失败"));
return false;
}else{ ReadFile(rFile,str,,&dwRet,NULL);
ss=str;
do{
index = ss.Find( ';' );
temp=ss.Left( index ) ;
n = temp.Find( ':' );
renyuan_name[num_renyuan]=temp.Left(n);
arr=temp.Right( temp.GetLength( )-n- ) ;
m = arr.Find( ',' );
renyuan_gonghao[num_renyuan]=arr.Left(m);
renyuan_danwei[num_renyuan]=arr.Right( arr.GetLength( )-m- ) ;
ss=ss.Right( ss.GetLength( )-index- );
num_renyuan++;
}while(ss.Find( ';' )!=-);
}
CloseHandle(rFile);

或者

memset(str,0,2000);
num_renyuan=0;
hFile =file.Open(_T("\\NANDFlash\\renyuan.txt"),CFile::modeRead );
if(hFile == -1){
AfxMessageBox(_T("file open error\n"));
}
file.Read(str, 2000);
ss=str;
do{
index = ss.Find( ';' );
temp=ss.Left( index ) ;
n = temp.Find( ':' );
renyuan_name[num_renyuan]=temp.Left(n);
arr=temp.Right( temp.GetLength( )-n-1 ) ;
m = arr.Find( ',' );
renyuan_gonghao[num_renyuan]=arr.Left(m);
renyuan_danwei[num_renyuan]=arr.Right( arr.GetLength( )-m-1 ) ;
ss=ss.Right( ss.GetLength( )-index-1 );
num_renyuan++; }while(ss.Find( ';' )!=-1);
file.Close();

  写文件代码:

//写入数据
HANDLE hFile;
DWORD dwRet; char str[2000]; hFile = CreateFile(_T("\\NANDFlash\\renyuan.txt"),GENERIC_READ | GENERIC_WRITE,0,NULL,TRUNCATE_EXISTING,0,NULL); if(hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("打开失败")); }else{
if(MessageBox(_T("确认删除用户,密码?"),_T("提示"),MB_OKCANCEL)==1)
{
int i,j;
//1.先将数据更新到数组,
for(i=0,j=0;i<num_renyuan;i++,j++)
{ if(i<flag||i>flag){
renyuan_name[j]=renyuan_name[i];
renyuan_gonghao[j]=renyuan_gonghao[i];
renyuan_danwei[j]=renyuan_danwei[i];
}else if(i==flag){
i++;
renyuan_name[j]=renyuan_name[i];
renyuan_gonghao[j]=renyuan_gonghao[i];
renyuan_danwei[j]=renyuan_danwei[i];
}
}
num_renyuan--;
//2.然后将数据从数组更新到文件中
for(i=0;i<num_renyuan;i++)
{
CString temp;//将temp清零
temp+=renyuan_name[i];
temp+=":";
temp+=renyuan_gonghao[i];
temp+=",";
temp+=renyuan_danwei[i];
temp+=";";
sprintf(str,"%S",temp);//S这样str就是完整的"username:passwors;",如果换成s,只会将一个字符传给str
WriteFile(hFile, str, strlen(str),&dwRet,NULL);
}
CloseHandle(hFile);
OnOK();
}
}

  

MFC笔记8的更多相关文章

  1. MFC笔记

    一.Win32基本程序概念 所有的windows程序都必须载入windows.h MFC程序都有一个Stdafx.h文件,它载入了MFC框架必须的文件. Windows程序以消息为基础,以事件驱动之. ...

  2. MFC笔记10

    1. CDC MemDC1; MemDC1.SetBkMode(OPAQUE); 背景模式,VC6下面有三种:/* Background Modes */#define TRANSPARENT 1// ...

  3. MFC笔记7

    1.VS中显示行号 工具 -> 选项 -> 文本编辑器 -> C/C++ -> 行号 2.VS中调整字体大小 工具 -> 选项 -> 环境->字体和颜色 3. ...

  4. MFC笔记6

    1.MFC文件的读写操作 写操作 创建一个编辑框(IDC_INFOR_EDIT1),在里面输入信息,创建一个按钮(IDC_BUTTON),点击按钮会触发(OnBnClickedButton2()函数) ...

  5. MFC笔记5

    1.MessageBox()             引用自(http://www.douban.com/note/40199603/) 一 函数原型及参数 function MessageBox(h ...

  6. MFC笔记3

    1. C6有默认的提示代码功能,但是其默认的快捷键是Ctrl + Space,这一般情况下是切换输入法快捷键,所以,只需重新设置一下快捷键就可以实现提示代码功能,具体设置位置如下: 工具(T) -&g ...

  7. MFC笔记2

    1.Create()函数创建,该函数原型如下: BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* ...

  8. MFC笔记1

    1.在对话框文档中定义两个定时器,每间隔5秒弹出一个消息框提示“定时器1”,每隔5秒弹出一个消息框提示“定时器2” UINT ID_TIMER1 = 1 , ID_TIMER2 = 2;   //设置 ...

  9. MFC笔记(DN)

    01:MFC应用程序编程 02:MFC菜单.工具栏.状态栏 03:视图窗口

  10. MFC笔记<持续更新>

    1.设置垂直滚动条的位置在末尾 SCROLLINFO si; GetScrollInfo(SB_VERT, &si, SIF_PAGE | SIF_RANGE | SIF_POS); si.f ...

随机推荐

  1. Python全栈之路----常用模块----time模块

    time 模块的方法 time.time():返回当前时间的时间戳. >>> import time >>> time.time() #从1974年到现在过去了多少 ...

  2. alpha冲刺(4/10)

    前言 队名:旅法师 作业链接 队长博客 燃尽图 会议 会议照片 会议内容 陈晓彬(组长) 今日进展: 召开会议 安排任务 博客撰写 问题困扰: pm和程序猿的交流到底应该怎么样呢,会出现,不做安排的任 ...

  3. 公众号及H5支付

    本篇主要记录微信支付中公众号及H5支付全过程. 1|1准备篇 公众号或者服务号(并开通微信支付功能).商户平台中开通JSAPI支付.H5支付. 1|2配置篇 公众号或者服务号中 -------开发-- ...

  4. python------SocketServer (0809)

    socket(一对一) 与socketserver 一.socketserver 1. 正式定义:The socketserver module simplifies the task of writ ...

  5. python 0,1行列问题

    shape[0]-- 行 A.min(0) --A的按列最小值,生成一个行向量 >>> a = np.random.rand(3,3) >>> a array([[ ...

  6. terraform 配置github module source

      terraform 支持多种module 的source 配置 以下是一个简单的使用github source的demo 测试项目 项目结构 ├── init.tpl ├── main.tf 代码 ...

  7. 请确保 ASP.NET State Service (ASP.NET 状态服务)已启动 问题解决

    当iis部署的网站访问遇到如下错误时: 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同.如 ...

  8. [转]c++访问python3-实例化类的方法

    转自: http://blog.csdn.net/love_clc/article/details/76653100 此文是学习笔记,供日后翻阅.下面列出C++访问python所需的函数,按调用的先后 ...

  9. flutter环境配置

    java环境安装 做基于android的原生app,首先需要安装java环境,需要到官网https://www.oracle.com/technetwork/java/javase/downloads ...

  10. HTML5 使用小结

    1.html5新增的常用元素 (a) <article.../>代表独立完整的一遍文章 (b)<section.../>对页面内容进行分块 (c)<nav.../> ...