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. Binary Search Tree Learning Summary

    BST Definition BST is short for Binary Search Tree, by definition, the value of right node is always ...

  2. 【paper】MTCNN

    参考 1. MTCNN笔记; 完

  3. install svn server in Ubuntu

    1. #安装服务 apt-get install subversionapt-get install libapache2-svnapt-get install apache2apt-get inst ...

  4. 列表:remove/del删除方法中的逻辑“误区”

    结果: list_1=["A","B","C","D","E","F",&quo ...

  5. GoStudy——解决vscode中golang插件依赖安装失败问题

    vscode中安装ms-vscode.go插件后可以开启对go语言的支持,ms-vscode.go插件需要依赖一些工具,安装完成后提示 Installing github.com/nsf/gocode ...

  6. day 44 JavaScript

    一.javascript简介 JavaScript是前台语言 JavaScript是前台语言,而不是后台语言. JavaScript运行在用户的终端网页上,而不是服务器上,所以我们称为“前台语言”.J ...

  7. 安装包安装npm

    在阿里云机器上centos7安装npm可以直接yum安装,然后基于镜像的时候安装不了,直接使用安装包安装,记录一下: 官网下载地址:https://nodejs.org/en/download/ #! ...

  8. ssh 22端口号拒绝

    1:当scp或者ssh登录ubuntu远程服务的时候,出现:

  9. 2.4 Visio2007显示动态对齐网格

  10. DataTable的详细用法

    在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...