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. 长度不超过n的连续最大和___优先队列

    题目链接: https://nanti.jisuanke.com/t/36116 题目: 在蒜厂年会上有一个抽奖,在一个环形的桌子上,有 nn 个纸团,每个纸团上写一个数字,表示你可以获得多少蒜币.但 ...

  2. python3 基础整理

    基础语法 1.python中区分大小写 2.查看关键字用 import keyword print (keyword.kwlist) 3.注释 #  单行注释,多行注释的快捷键是ctr+/,取消注释的 ...

  3. js封装选项卡

    <div class="forestcamp_box"> <img src="img/home_02.jpg" /> <div c ...

  4. Dijkstra(迪杰斯特拉)模板

    直接将模板封装在结构体里面. struct Edge{ int from,to,dist; Edge(int u, int v,int d): from(u),to(v),dist(d){} }; s ...

  5. solr实现动态加载分词

    版本是5.3.0 在core(自己创建的模块)的schema.xml里面增加类型: <fieldType name="text_lj" class="solr.Te ...

  6. HTML超链接和路径

    html超链接和路径 学习要点:     1.超链接的属性     2.相对与绝对路径     3.锚点设置                          一.超链接的属性     <a&g ...

  7. 在jsp中应如何避免,request.getContextPath();等get报错问题

    导致request中的大部分get方法无法获取,是因为没有依赖的jar包.就像这样.这里不仅仅有getContextPath()方法报错,如果存在这个问题,大部分的request方法都不可用. 解决这 ...

  8. 加载XML文件到系统中

    using System;using System.Data;using System.IO;using System.Xml;using System.Collections.Generic; na ...

  9. zombodb 索引管理

    zombodb 支持标准的index 管理(create .alter.drop) 创建索引 CREATE INDEX index_name ON table_name USING zombodb ( ...

  10. ILBC 规范 2

    接上篇 <ILBC 规范>  https://www.cnblogs.com/KSongKing/p/10354824.html  , ILBC    的 目标 是    跨平台  跨设备 ...