码迷,mamicode.com
首页 > 其他好文 > 详细

获取ini文件所有的Sections和Keys

时间:2016-04-29 23:37:18      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

获取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

 

获取ini文件所有的Sections和Keys

标签:

原文地址:http://www.cnblogs.com/enjoyzhao/p/5447742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!