Properties file library for C (or C++)(C(或 C++)的属性文件库)
问题描述
标题一目了然:有谁知道 C 或 C++ 的(好的)属性文件阅读器库吗?
The title is pretty self-explanatory: does anyone know of a (good) properties file reader library for C or, if not, C++?
具体来说,我想要一个处理 Java 中使用的 .properties 文件格式的库:http://en.wikipedia.org/wiki/.properties
To be specific, I want a library which handles the .properties file format used in Java: http://en.wikipedia.org/wiki/.properties
推荐答案
STLSoft 的 1.10 alpha 包含一个 platformstl::properties_file
类.它可用于从文件中读取:
STLSoft's 1.10 alpha contains a platformstl::properties_file
class. It can be used to read from a file:
using platformstl::properties_file;
properties_file properties("stuff.properties");
properties_file::value_type value = properties["name"];
或从记忆中:
properties_file properties(
"name0=value1
name1 value1
name\ 2 : value\ 2 ",
properties_file::contents);
properties_file::value_type value0 = properties["name0"];
properties_file::value_type value1 = properties["name1"];
properties_file::value_type value2 = properties["name 2"];
看起来最新的 1.10 版本有一堆全面的单元测试,并且他们已经升级了类来处理 Java 文档.
Looks like the latest 1.10 release has a bunch of comprehensive unit-tests, and that they've upgraded the class to handle all the rules and examples given in the Java documentation.
唯一明显的问题是 value_type
是 stlsoft::basic_string_view
(在 这篇 Dobb 博士的文章中描述a>),它有点类似于 std::string
,但实际上并不拥有它的内存.据推测,他们这样做是为了避免不必要的分配,大概是出于性能原因,这是 STLSoft 设计所珍视的.但这意味着你不能只写
The only apparent rub is that the value_type
is an instance of stlsoft::basic_string_view
(described in this Dr Dobb's article), which is somewhat similar to std::string
, but doesn't actually own its memory. Presumably they do this to avoid unneccessary allocations, presumably for performance reasons, which is something the STLSoft design holds dear. But it means that you can't just write
std::string value0 = properties["name0"];
但是,您可以这样做:
std::string value0 = properties["name0"].c_str();
还有这个:
std::cout << properties["name0"];
我不确定我是否同意这个设计决定,因为从文件或内存中读取属性的可能性有多大,需要绝对的最后一个周期.我认为他们应该将其更改为默认使用 std::string
,然后在明确需要时使用字符串视图".
I'm not sure I agree with this design decision, since how likely is it that reading properties - from file or from memory - is going to need the absolute last cycle. I think they should change it to use std::string
by default, and then use the "string view" if explicitly required.
除此之外,properties_file
类看起来可以解决问题.
Other than that, the properties_file
class looks like it does the trick.
这篇关于C(或 C++)的属性文件库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C(或 C++)的属性文件库


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01