Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译基本Boost PropertyTree示例时出现问题-编译错误。怎么办?_C++_Visual Studio_Visual Studio 2010_Boost_Boost Propertytree - Fatal编程技术网

C++ 编译基本Boost PropertyTree示例时出现问题-编译错误。怎么办?

C++ 编译基本Boost PropertyTree示例时出现问题-编译错误。怎么办?,c++,visual-studio,visual-studio-2010,boost,boost-propertytree,C++,Visual Studio,Visual Studio 2010,Boost,Boost Propertytree,因此,我尝试在visual studio 2008上编译它,并在VS2010上编译它。get错误C2228:left of'.put\u value'必须具有class/struct/union c:\program files(x86)\boost-1.46.1\include\boost\property\u tree\detail\ptree\u implementation.hpp 795 1 以下是我使用的代码: #include <stdio.h> #include &l

因此,我尝试在visual studio 2008上编译它,并在VS2010上编译它。get
错误C2228:left of'.put\u value'必须具有class/struct/union c:\program files(x86)\boost-1.46.1\include\boost\property\u tree\detail\ptree\u implementation.hpp 795 1

以下是我使用的代码:

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <set>
#include <sstream>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

using namespace std;

std::string m_file;          // log filename
int m_level;                 // debug level
std::set<string> m_modules;  // modules where logging is enabled

// Loads debug_settings structure from the specified XML file
void load( std::ifstream &file)
{
    // Create an empty property tree object
    using boost::property_tree::ptree;
    ptree pt;

    // Load the XML file into the property tree. If reading fails
    // (cannot open file, parse error), an exception is thrown.
    read_xml(file, pt);

    // Get the filename and store it in the m_file variable.
    // Note that we construct the path to the value by separating
    // the individual keys with dots. If dots appear in the keys,
    // a path type with a different separator can be used.
    // If the debug.filename key is not found, an exception is thrown.
    m_file = pt.get<std::string>("debug.filename");

    // Get the debug level and store it in the m_level variable.
    // This is another version of the get method: if the value is
    // not found, the default value (specified by the second
    // parameter) is returned instead. The type of the value
    // extracted is determined by the type of the second parameter,
    // so we can simply write get(...) instead of get<int>(...).
    m_level = pt.get("debug.level", 0);

    // Iterate over the debug.modules section and store all found
    // modules in the m_modules set. The get_child() function
    // returns a reference to the child at the specified path; if
    // there is no such child, it throws. Property tree iterators
    // are models of BidirectionalIterator.
    BOOST_FOREACH(ptree::value_type &v,
        pt.get_child("debug.modules"))
        m_modules.insert(v.second.data());
}

// Saves the debug_settings structure to the specified XML file
void save(const std::string &filename)
{
    // Create an empty property tree object
    using boost::property_tree::ptree;
    ptree pt;

    // Put log filename in property tree
    pt.put("debug.filename", m_file);

    // Put debug level in property tree
    pt.put("debug.level", m_level);

    // Iterate over the modules in the set and put them in the
    // property tree. Note that the put function places the new
    // key at the end of the list of keys. This is fine most of
    // the time. If you want to place an item at some other place
    // (i.e. at the front or somewhere in the middle), this can
    // be achieved using a combination of the insert and put_own
    // functions.
    BOOST_FOREACH(const std::string &name, m_modules)
        pt.put("debug.modules.module", name, true);

    // Write the property tree to the XML file.
    write_xml(filename, pt);
}

int main()
{
    std::ifstream script( "<debug>\n   <filename>debug.log</filename>\n    <modules>\n        <module>Finance</module>\n       <module>Admin</module>\n        <module>HR</module>\n    </modules>\n    <level>2</level>\n</debug>\n");
    load(script);
    save("j.js");
    cout << "parse complete" << endl;
    cin.get();
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
std::string m_file;//日志文件名
int m_level;//调试级别
std::设置m_模块;//启用日志记录的模块
//从指定的XML文件加载调试\u设置结构
无效加载(标准::ifstream和文件)
{
//创建一个空的属性树对象
使用boost::property_tree::ptree;
ptree-pt;
//将XML文件加载到属性树中。如果读取失败
//(无法打开文件,分析错误),引发异常。
读取xml(文件,pt);
//获取文件名并将其存储在m_file变量中。
//请注意,我们通过分隔来构造值的路径
//带点的各个键。如果键中出现点,
//可以使用具有不同分隔符的路径类型。
//如果未找到debug.filename键,将引发异常。
m_file=pt.get(“debug.filename”);
//获取调试级别并将其存储在m_level变量中。
//这是get方法的另一个版本:如果值为
//未找到,默认值(由第二个
//而是返回参数)。值的类型
//提取由第二个参数的类型决定,
//因此,我们可以简单地编写get(…)而不是get(…)。
m_level=pt.get(“debug.level”,0);
//迭代debug.modules部分并存储所有找到的
//m_模块集中的模块。get_child()函数
//返回对指定路径上的子级的引用;如果
//没有这样的子级,它抛出.Property树迭代器
//是双向转换器的模型。
增压器(树::值类型和v,
pt.get_子项(“debug.modules”))
m_modules.insert(v.second.data());
}
//将调试设置结构保存到指定的XML文件
无效保存(const std::string和filename)
{
//创建一个空的属性树对象
使用boost::property_tree::ptree;
ptree-pt;
//将日志文件名放在属性树中
pt.put(“debug.filename”,m_文件);
//将调试级别放在属性树中
pt.put(“调试级”,m_级);
//迭代集合中的模块并将它们放入
//属性树。请注意,put函数放置新的
//键列表末尾的键。这在大多数情况下都很好
//时间。如果你想在其他地方放置物品
//(即在前面或中间的某个地方),这可以
//可以使用插入和放置的组合来实现
//功能。
BOOST_FOREACH(const std::string和name,m_模块)
pt.put(“debug.modules.module”,名称,true);
//将属性树写入XML文件。
写入xml(文件名,pt);
}
int main()
{
std::ifstream脚本(“\n debug.log\n\n Finance\n Admin\n HR\n\n 2\n\n”);
加载(脚本);
保存(“j.js”);

cout1.46.1的示例代码已更改:

相关的变化是

BOOST_FOREACH(const std::string和name,m_模块)
pt.add(“debug.modules.module”,name);

也许您可以将编译器抱怨的文件795行复制到您的问题中,以便我们查看。