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);//验证信息

相关推荐
Pafey2 天前
MFC中一个类的成员变量值自动被篡改:多重继承带来的问题
c++·mfc
夜月yeyue8 天前
个人写HTOS移植shell
c++·mcu·算法·性能优化·架构·mfc
ningbinzhang8 天前
MFC 获取域名TXT记录内容
c++·mfc
ajassi200018 天前
开源 C# 快速开发(六)自定义控件--圆环
开源·c#·mfc
ajassi200018 天前
开源 C# 快速开发(七)通讯--串口
开源·c#·mfc
追烽少年x20 天前
MFC中开源布局库---ResizableLib
mfc
_不会dp不改名_21 天前
C++开源库使用:nlohmann/json
c++·json·mfc
阿昭L1 个月前
MFC仿真
c++·mfc
怎么没有名字注册了啊1 个月前
MFC_Install_Create
c++·mfc
Humbunklung1 个月前
unordered_map使用MFC的CString作为键值遇到C2056和C2064错误
c++·stl·mfc