C ++无法解析变量BOOST_FOREACH

Ori*_*ael 1 c++ boost clion

我试图使用Boost库,我复制了整个boost文件夹,除了docs,libs,more,status,tools文件夹。

当我尝试使用下面的代码块时,我的编译器无法识别2件事情。

vector<string>* read(string & filename)
{


 // populate tree structure pt
    using boost::property_tree::ptree;
    ptree pt;
    read_xml(filename, pt);
    ptree tree;

vector<string> *ans = new vector<string>();

BOOST_FOREACH( ptree::value_type &v, pt.get_child("computer"))
{
    string name = v.first.get<string>("name");
    string OS = v.first.get<string>("OS");

    ans->push_back(name);
    ans->push_back(OS);
}

return ans;
}
Run Code Online (Sandbox Code Playgroud)
  1. 未在此范围内声明“ BOOST_FOREACH”
  2. 无法解析结构成员“ value_type”

我知道以下包含行应该足够了:

#include <iostream>
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请询问。TIA

编辑

添加include foreach.hpp后,即时通讯功能得到:

这个问题

seh*_*ehe 5

我知道以下包含行应该足够了:

显然他们不是。加

#include <boost/foreach.hpp>
Run Code Online (Sandbox Code Playgroud)

固定代码:

Live On Coliru

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

std::vector<std::string> read(std::string & filename)
{
    // populate tree structure pt
    using boost::property_tree::ptree;

    ptree pt;
    read_xml(filename, pt);
    ptree tree;

    std::vector<std::string> ans;

    BOOST_FOREACH(ptree::value_type &v, pt.get_child("computer"))
    {
        std::string name = v.second.get<std::string>("name");
        std::string OS   = v.second.get<std::string>("OS");

        ans.push_back(name);
        ans.push_back(OS);
    }

    return ans;
}

int main()
{
}
Run Code Online (Sandbox Code Playgroud)