获取ini文件中所有块的特定字段值

#include <vector>
#include <string>
#include <iostream>
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib,"shlwapi.lib")

std::vector<std::string> m_sections;
int _tmain(int argc, _TCHAR* argv[])
{
	char szModule[MAX_PATH] = {0};
	GetModuleFileName(NULL,szModule,MAX_PATH);
	PathRemoveFileSpec(szModule);
	PathAppend(szModule,"SoftInfo.ini");
	char sections[2000] ={0};
	GetPrivateProfileSectionNames(sections,2000,szModule);

	char szSection[MAX_PATH] = {0};
	int iPos = 0;
	for (int i=0; i<2000; ++i)
	{
		if (szSection[0] != '\0' && '\0' == sections[i+1] && '\0' == sections[i+2])
		{
			szSection[iPos]=0;
			m_sections.push_back(szSection);
			break;
		}
		szSection[iPos++] = sections[i];
		if ('\0' == sections[i])
		{
			iPos = 0;
			m_sections.push_back(szSection);
			ZeroMemory(szSection, MAX_PATH);
		}
	}
	for (int i=0; i< m_sections.size(); ++i)
	{
		char softName[MAX_PATH] = {0};
		GetPrivateProfileString(m_sections[i].c_str(),"SoftName","",softName,MAX_PATH,szModule);
		std::cout<<softName<<std::endl;
	}

	std::cout<<"*********************************************"<<std::endl;

	system("pause");
	return 0;
}


上面的代码打印出了程序所在目录的SoftInfo.ini中所有区块的SoftName字段的键值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值