在std::map中使用TiXmlElement矢量

Using TiXmlElement vector in std::map

本文关键字:TiXmlElement 矢量 std map      更新时间:2023-10-16

在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.0vcincludexstddef  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.0vcincludexstddef  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.0vcincludexstddef  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.0vcincludexstddef  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.0vcincludexstddef  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.0vcincludexstddef  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.0vcincludexstddef  180

首先,我无法理解出了什么问题,但我知道vector<TiXmlElement*>有错误。请指引我正确的方向。非常感谢。

缺少#include <string>

它在错误1中:运算符<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.0vcincludexstddef  180