相关疑难解决方法(0)

使用Boost解析XML属性

我想与您分享我在尝试使用Boost库(版本1.52.0)处理C++中XML元素的某些属性时遇到的问题.给出以下代码:

#define ATTR_SET ".<xmlattr>"
#define XML_PATH1 "./pets.xml"

#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

using namespace std;
using namespace boost;
using namespace boost::property_tree;

const ptree& empty_ptree(){
    static ptree t;
    return t;
}

int main() {
    ptree tree;
    read_xml(XML_PATH1, tree);
    const ptree & formats = tree.get_child("pets", empty_ptree());
    BOOST_FOREACH(const ptree::value_type & f, formats){
        string at = f.first + ATTR_SET;
        const ptree & attributes = formats.get_child(at, empty_ptree());
        cout << "Extracting attributes from " << at << ":" << endl;
        BOOST_FOREACH(const …
Run Code Online (Sandbox Code Playgroud)

c++ xml boost boost-propertytree

17
推荐指数
1
解决办法
3万
查看次数

如何使用 C++ 读取/写入 JSON?

我想知道如何使用 C++ 读取/写入 JSON 文件。我将使用此文件来存储我正在制作的简单游戏的玩家信息和设置。这没什么花哨的,只是一个控制台猜数字游戏,但我只是用它来学习东西。

我必须知道如何读取和写入 JSON 的特定部分。

c++ json

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×2

boost ×1

boost-propertytree ×1

json ×1

xml ×1