获取ini文件所有的Sections和Keys

获取ini文件中所有的Sections和Keys,并以pair对的方式存入到vector中

 1 #include <iostream>
 2 #include <windows.h>
 3 #include <string>
 4 #include <vector>
 5 using namespace std;
 6 
 7 #define PATH "E:\\vc_code\\parse_ini\\cfg.ini"
 8 int main()
 9 {
10     char buff[1024] = {0};
11     vector<string> vecSections;
12     vector<string> vecKeys;
13     vector<pair<string, string>> vecSectionKey;
14     int num = GetPrivateProfileSectionNames(buff, 1024, PATH);
15     size_t startpos = 0;
16     for (size_t i = 0; i < num; ++i)
17     {
18         if ('\0' == buff[i])
19         {
20             string tmp(buff + startpos, buff + i);
21             startpos = i + 1;
22             vecSections.push_back(tmp);
23         }
24     }
25     
26     for (size_t i = 0; i < vecSections.size(); ++i)
27     {
28         char buffkey[1024] = {0};
29         num = GetPrivateProfileSection(vecSections[i].c_str(), buffkey, 1024, PATH);
30         startpos = 0;
31         for (size_t j = 0; j < num; ++j)
32         {
33             if ('\0' == buffkey[j])
34             {
35                 string tmp(buffkey + startpos, buffkey + j);
36                 startpos = j + 1;
37                 size_t pos = tmp.find('=');
38                 vecKeys.push_back(tmp.substr(0, pos));
39 
40                 vecSectionKey.push_back(make_pair(vecSections[i], tmp.substr(0, pos)));
41             }
42         }
43     }
44     
45     return 0;
46 }
View Code

 

转载于:https://www.cnblogs.com/enjoyzhao/p/5447742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值