How to feed Boost.PropertyTree with a string, not a file?

前端 未结 3 998
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 16:32

Boost has a tutorial on how to load XML from a file. How do I feed it with a string that I either create in code or receive from a user (e.g. with cin)?

3条回答
  •  清歌不尽
    2021-01-01 17:15

    Heres some code that works for me...

    // Create an empty property tree object
    ptree xmlTree;
    
    // Read the XML config string into the property tree. Catch any exception
    try {
      stringstream ss; ss << xmlConfigString;
      read_xml(ss, xmlTree);
    }
    catch (xml_parser_error &e) {
      LOGERROR ("Failed to read config xml " << e.what());
    }
    catch (...) {
      LOGERROR ("Failed to read config xml with unknown error");
    }
    

提交回复
热议问题