【问题标题】:ptree iterator members not identifed by autocomplete?ptree 迭代器成员未被自动完成识别?
【发布时间】:2015-01-13 21:26:23
【问题描述】:

我正在使用 boost 库来解析 .ini 文件,如下所示:

[head]
type1=val1
type2=cal2
...

我的代码是这样的:

#include <iostream>
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
using namespace std;

int main()
{
    using boost::property_tree::ptree;

    boost::property_tree::ptree pt;
    boost::property_tree::ini_parser::read_ini("test.ini", pt);

    boost::property_tree::ptree::iterator pos1,pos2;

    for(pos1 = pt.begin(); pos1 != pt.end() ; ++pos1)
    {
        cout << pos1->first << endl;

        for(pos2 = pos1->second.begin() ; pos2 != pos1->second.end() ; ++pos2)
        {
            cout << "    " << pos2->first << "=" << pos2->second.get_value<string>() << endl;
        }
        cout << endl;
    }

    return 0;
}

一切正常,程序输出符合预期,但 eclipse 将所有 pos1 和 pos2“->”标记为错误......智能感知不会加载“第一”或“第二”选项并标记它们的所有用途作为错误...但一切都编译...

有什么想法吗??

这是它的外观:

【问题讨论】:

    标签: c++ pointers boost autocomplete ptree


    【解决方案1】:

    pos1pos2 不是指针,您应该使用. 而不是-&gt;

    【讨论】:

    • 嗨,Eric,也许我不太了解迭代器的概念,但我认为 pos1 和 pos2 是指向它们正在迭代的同一类型的指针(至少这是它对我的数组的工作方式和向量迭代器)。无论如何,当我只使用“pos1”时。我得到了很多迭代器属性和方法,但没有任何 ptree 的......
    猜你喜欢
    • 2012-03-16
    • 2015-04-30
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多