Boost Property_Tree iterators, how to handle them?

前端 未结 3 1201
野的像风
野的像风 2021-02-07 10:00

I am sorry, I asked a question about the same topic before, but my problem concerns another aspect of the one described there (How to iterate a boost...).

Take a look at

3条回答
  •  滥情空心
    2021-02-07 10:39

    You should have the prior knowledge on the input property file.

    Boost property tree is not a general document parser. It will do parsing and give access to the data, but must locate it manually.

    I don't know there are method to navigate whole document, but if you only need the properties of your own file you can do it with very simple code.

    From the boost documentation:

    1) The throwing version (get):

    ptree pt;
    /* ... */
    float v = pt.get("a.path.to.float.value");
    

    2) The default-value version (get):

    ptree pt;
    /* ... */
    float v = pt.get("a.path.to.float.value", -1.f);
    

    3) The optional version (get_optional):

    ptree pt;
    /* ... */
    boost::optional v = pt.get_optional("a.path.to.float.value");
    

提交回复
热议问题