MFC中使用函数实现ini文件的连续读写

实现的思路:

首先通过读取文件中的count值,确定当前信息条数;

第二步:将count进行累加,把信息写到累加后的键值"="的后面;

第三步:写入count累加值,实现连续读写;

第四步:写入需要保存的信息;

第五步:读取当前count值;

第六步:根据当前count值,读取写入的信息;

最后就是通过MessageBox来验证写入的信息。

//读取Ini文件中的Count值

GetPrivateProfileString(L"FileName", L"Count", NULL, wcharBuf, MAX_PATH, L"C:\\Users\\source\\repos\\FileNameInfo.ini");

//读到后累加一,wchar_t转int再转CString,实现连续读写

CountNumb = _ttol(wcharBuf) + 1;

StrCountNum.Format(_T("%d"), CountNumb);

//合成Result+number(键值)

KeyName = StrKey + StrCountNum;

//写入count累加值

::WritePrivateProfileString(L"FileName", L"Count", StrCountNum, L"C:\\Users\\source\\repos\\FileNameInfo.ini");

//写入结果strTempEditPath

::WritePrivateProfileString(L"FileName", KeyName, strTempEditPath, L"C:\\Users\\source\\repos\\FileNameInfo.ini");

//获取当前count值

GetPrivateProfileString(L"FileName", L"Count", NULL, wcharBuf, MAX_PATH, L"C:\\Users\\source\\repos\\FileNameInfo.ini");

//获取当前Result+number(键值)后的数据

GetPrivateProfileString(L"FileName", KeyName, NULL, wcharBuf, MAX_PATH, L"C:\\Users\\source\\repos\\FileNameInfo.ini");

//将读取到的数据存到CString 变量中

strSearch = wcharBuf;

//从右边开始截取

strFileName = strSearch.Right(strSearch.GetLength()-39);

//MessageBox(strFileName);//验证信息

相关推荐
霜晨月c9 小时前
MFC 使用细节
笔记·学习·mfc
waf139163 天前
MFC中使用OpenCV动态绘制图像ROI区域(矩形+多边形)
c++·图像处理·mfc
兵哥工控4 天前
MFC工控项目实例之十六输入信号验证
c++·mfc
zixingcai5 天前
MFC修改控件ID的详细说明
c++·mfc
兵哥工控5 天前
MFC工控项目实例之十五定时刷新PC6325A模拟量输入
c++·mfc
爱上杨小厨6 天前
MFC实现对话框与控件的自适应调节
c++·mfc
Bill666 天前
MFC之CString类及其成员函数用法详解
c++·mfc
兵哥工控9 天前
MFC工控项目实例之十三从文件读写板卡信号名称
c++·mfc
傻啦嘿哟9 天前
通过Python调用Excel VBA宏:扩展自动化能力的深度探索
c++·mfc
halcyonfreed10 天前
2.3.2 协程调度器实现与性能测试
c++·mfc