在std :: map中使用TiXmlElement向量

时间:2014-09-08 07:42:52

标签: c++ visual-studio-2012 vector tinyxml

在std :: map中使用tinyxml API的TiXmlElement向量时,visual studio会给出编译时错误。我的代码是......

#include "tinyxml.h"
#include <vector>
#include <iostream>
#include <map>

using namespace std;
class childCounter 
{
public:
    childCounter(void);
    std::map<string,std::vector<TiXmlElement*>> childrenList;

    int count(const TiXmlElement&,const TiXmlAttribute*);
    ~childCounter(void);
};


int childCounter::count(const TiXmlElement& ele,const TiXmlAttribute* attr)
{
    int count = 0;

    std::map<string,std::vector<TiXmlElement*>> childList;
    std::vector<TiXmlElement*> childVector;
    TiXmlElement *ele = new TiXmlElement("ChildOne");
    childVector.push_back(ele);
    string name = "entry";
    childList[name] = childVector;

    return count;
}

编译错误

Error   1   error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'    c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180
Error   2   error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'    c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180
Error   3   error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const std::string'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180
Error   4   error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180
Error   5   error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'   c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180

Error   6   error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180
Error   7   error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180

首先,我无法理解出了什么问题,但我开始知道错误是vector<TiXmlElement*>。请指导我正确的方向。谢谢。

1 个答案:

答案 0 :(得分:2)

缺少#include <string>

错误1:运营商&lt;缺少std :: string,因为树特征不可删除。

Error   1   error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'    c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  180