标签:
获取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 }
标签:
原文地址:http://www.cnblogs.com/enjoyzhao/p/5447742.html