大佬教程收集整理的这篇文章主要介绍了迭代c上的ini文件,可能使用boost :: property_tree :: ptree?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Apple = 1 Orange = 2 XYZ = 3950
但我不知道可用密钥的集合.我使用C#解析这个文件比较容易,让我演示源代码:
public static Dictionary<String,String> ReadParametersFromFile(String path) { String[] linesDirty = File.ReadAllLines(path); String[] lines = linesDirty.Where( str => !String.IsNullOrWhiteSpace(str) && !str.StartsWith("//")).ToArray(); var Dict = lines.SELEct(s => s.Split(new char[] { '=' })) .ToDictionary(s => s[0].Trim(),s => s[1].Trim()); return Dict; }
现在我只需要用c做同样的事情.我在考虑使用boost :: property_tree :: ptree但是我似乎无法迭代ini文件.它很容易阅读ini文件:
boost::property_tree::ptree pt; boost::property_tree::ini_parser::read_ini(path,pt);
但是不可能迭代它,请参考这个问题Boost program options – get all entries in section
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ini_parser.hpp> int main() { using boost::property_tree::ptree; ptree pt; read_ini("input.txt",pt); for (auto& section : pt) { std::cout << '[' << section.first << "]\n"; for (auto& key : section.second) std::cout << key.first << "=" << key.second.get_value<std::string>() << "\n"; } }
这导致输出如下:
[Cat1] name1=100 #skipped name2=200 \#not \\skipped name3=dhfj dhjgfd [Cat_2] UsagePage=9 Usage=19 Offset=0x1204 [Cat_3] UsagePage=12 Usage=39 Offset=0x12304
我之前使用boost-spirit编写了@L_262_12@非常全功能的Inifile解析器:
> Cross-platform way to get line number of an INI file where given option was found
(作为奖励,它可选地记录所有已解析元素的确切源位置,这是该问题的主题).
不过,为了您的目的,我想我会推荐Boost Property Tree.
以上是大佬教程为你收集整理的迭代c上的ini文件,可能使用boost :: property_tree :: ptree?全部内容,希望文章能够帮你解决迭代c上的ini文件,可能使用boost :: property_tree :: ptree?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。