
正文
获取ini文件所有的Sections和Keys
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
获取ini文件中所有的Sections和Keys,并以pair对的方式存入到vector中
#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
using namespace std; #define PATH "E:\\vc_code\\parse_ini\\cfg.ini"
int main()
{
char buff[] = {};
vector<string> vecSections;
vector<string> vecKeys;
vector<pair<string, string>> vecSectionKey;
int num = GetPrivateProfileSectionNames(buff, , PATH);
size_t startpos = ;
for (size_t i = ; i < num; ++i)
{
if ('\0' == buff[i])
{
string tmp(buff + startpos, buff + i);
startpos = i + ;
vecSections.push_back(tmp);
}
} for (size_t i = ; i < vecSections.size(); ++i)
{
char buffkey[] = {};
num = GetPrivateProfileSection(vecSections[i].c_str(), buffkey, , PATH);
startpos = ;
for (size_t j = ; j < num; ++j)
{
if ('\0' == buffkey[j])
{
string tmp(buffkey + startpos, buffkey + j);
startpos = j + ;
size_t pos = tmp.find('=');
vecKeys.push_back(tmp.substr(, pos)); vecSectionKey.push_back(make_pair(vecSections[i], tmp.substr(, pos)));
}
}
} return ;
}







