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

相关推荐
何以解忧,唯有..5 天前
Go 语言数据类型详解:从基础到复合类型
开发语言·golang·mfc
tiandyoin6 天前
MFC奇怪问题--连续窗口ID,关闭其中一个才能打开另一个
dialog·mfc·vc++·ws_child·mdi
兵哥工控11 天前
高精度微秒延时函数实现顺控工控项目实例
c++·mfc·硬件高精度计时器
兵哥工控12 天前
MFC开关量输出发脉冲实例
c++·mfc·开关量发脉冲
ZK_H14 天前
MFC学习——简易计算器以及跨应用通信
学习·5g·mfc
ZK_H15 天前
MFC程序开发自学笔记其一——windows应用程序与c++基础
c++·笔记·mfc
还在点灯@20 天前
基于visual studio的MFC上位机实现界面切换
c++·visualstudio·mfc
徐安安_ye123 天前
FlashAttention与文本生成:让AI妙笔生花
c++·人工智能·mfc
兵哥工控24 天前
MFC 动态数组CArray类使用说明实例
c++·mfc
ytttr87325 天前
OPC UA 协议栈 C 语言实现
c语言·开发语言·mfc