Skip to content

Instantly share code, notes, and snippets.

@ifukazoo
Created January 2, 2016 00:24
Show Gist options
  • Save ifukazoo/ee62a3fcfd1ee35bf46f to your computer and use it in GitHub Desktop.
Save ifukazoo/ee62a3fcfd1ee35bf46f to your computer and use it in GitHub Desktop.
INIファイルからkeyvalのmapを作る
#include <map>
#include <string>
std::map<std::string, std::map<std::string, std::string>>
GetPrivateProfileMap(std::string inifile)
{
std::map<std::string, std::map<std::string, std::string>> mainmap;
char sections[8192], keys[8192], value[8192];
::GetPrivateProfileString(NULL, NULL, "", sections, sizeof(sections), inifile.c_str());
char* section = sections;
while (*section) {
std::map<std::string, std::string> keyval;
::GetPrivateProfileString(section, NULL, "", keys, sizeof(keys), inifile.c_str());
char* key = keys;
while (*key) {
::GetPrivateProfileString(section, key, "", value, sizeof(value), inifile.c_str());
keyval.insert(std::make_pair(std::string(key), std::string(value)));
key += strlen(key) + 1;
}
mainmap.insert(std::make_pair(std::string(section), keyval));
section += strlen(section) + 1;
}
return mainmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment