以文件名作为键的 Boost 属性树
我试图使用文件名作为 boost:: PropertyTree
然而,'.'文件名中的字符(例如“example.txt”)会导致在属性树中添加附加层。最明显的解决方案是替换“.”与另一个字符,但可能有更好的方法来做到这一点,例如使用转义字符。
在以下示例中,值 10 将被放入节点“txt”(“example”的子节点)中。相反,我希望将值 10 存储在节点“example.txt”中。
ptree pt;
pt.put("example.txt", 10);
如何使用单个节点的完整文件名?
提前感谢您的帮助!
I am trying to use filenames as the key in boost::PropertyTree
However, the '.' character in a filename such as "example.txt" causes an additional layer to be added within the property tree. The most obvious solution would be to replace '.' with another character, but there is likely a better way to do this, such as with an escape character.
In the following example, the value 10 will be put in the node 'txt', a child of 'example'. Instead, I want the value 10 to be stored in the node 'example.txt'.
ptree pt;
pt.put("example.txt", 10);
How can I use the full filename for a single node?
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需显式插入树即可:
put
方法只是为了方便起见,这就是它自动将.
解析为附加层的原因。像我上面所示的那样显式构造 value_type 可以避免这个问题。解决该问题的另一种方法是在
put
和get
中使用额外的参数,这会更改分隔符。根据记录,我以前从未使用过这个类。我从您链接到的页面直接获取了所有这些信息; )
Just insert the tree explicitly:
The
put
method is simply there for convenience, which is why it automatically parses.
as an additional layer. Constructing the value_type explicitly like I have shown above avoids this problem.An alternative way to solve the problem is to use an extra argument in
put
andget
, which changes the delimeter.For the record, I've never used this class before in my life. I got all this information right from the page you linked to ; )
问题是文档已经过时了。必须按如下方式创建路径类型对象,并使用另一个对于指定为分隔符的文件路径无效的字符,如下所示:
我从新闻组 gmane.comp.lib.boost.devel 的 boost 邮件列表中找到了解决方案的路径由菲利普·沃彻发布。
The problem was that the documentation was outdated. A path type object must be created as follows, with another character that is invalid for file paths specified as the delimiter as follows:
I found a path to the solution from the boost mailing list at the newsgroup gmane.comp.lib.boost.devel posted by Philippe Vaucher.