获取ini文件所有的Sections和Keys
2016-04-29 22:23
295 查看
获取ini文件中所有的Sections和Keys,并以pair对的方式存入到vector中
View Code
#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[1024] = {0}; vector<string> vecSections; vector<string> vecKeys; vector<pair<string, string>> vecSectionKey; int num = GetPrivateProfileSectionNames(buff, 1024, PATH); size_t startpos = 0; for (size_t i = 0; i < num; ++i) { if ('\0' == buff[i]) { string tmp(buff + startpos, buff + i); startpos = i + 1; vecSections.push_back(tmp); } } for (size_t i = 0; i < vecSections.size(); ++i) { char buffkey[1024] = {0}; num = GetPrivateProfileSection(vecSections[i].c_str(), buffkey, 1024, PATH); startpos = 0; for (size_t j = 0; j < num; ++j) { if ('\0' == buffkey[j]) { string tmp(buffkey + startpos, buffkey + j); startpos = j + 1; size_t pos = tmp.find('='); vecKeys.push_back(tmp.substr(0, pos)); vecSectionKey.push_back(make_pair(vecSections[i], tmp.substr(0, pos))); } } } return 0; }
View Code
相关文章推荐
- setContentView、findViewById 和 inflate 的区别?
- 第四课 初识系统调用
- 滑动窗口的最大值
- UVA 489 - Hangman Judge 未解决未解决未解决未解决
- Linux期末总结
- Linux内核学习总结(final)
- Asp.Net MVC3 简单入门详解过滤器Filter
- tomcat配置虚拟目录
- 1013 Problem M
- POJ 2243 Knight Moves(BFS)
- 最大序列和
- 文件操作
- 项目经理多年的经验之谈
- windows通讯端口初始化失败
- 工具类Log
- 使用KMS批量激活操作系统
- 删除ORacle 命名空间
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 冲刺第六天
- 15.oracle的dump理解十五 SQL命令DUMP