String Can';t从c+;中的XML解析类获取字符串+;?

String Can';t从c+;中的XML解析类获取字符串+;?,string,visual-c++,casting,hashmap,String,Visual C++,Casting,Hashmap,我用下面的代码解析C++中的XML文件…p> 现在我想在hashmap中填充数据。但我做不到。错误表示无法从BSTR转换为std::字符串 这是代码的一部分 MSXML2::IXMLDOMNode *pIParentNode = NULL; //Variables to store attribute's name,type and text: BSTR bstrAttrName, bstrAttrType, bstrAttrText; typedef std::tr

我用下面的代码解析C++中的XML文件…p> 现在我想在hashmap中填充数据。但我做不到。错误表示无法从BSTR转换为std::字符串

这是代码的一部分

 MSXML2::IXMLDOMNode *pIParentNode = NULL;
 //Variables to store attribute's name,type and text:    
      BSTR bstrAttrName, bstrAttrType, bstrAttrText;

 typedef std::tr1::unordered_map< std::string, std::string > hashmap;     
      hashmap numbers;

      for(i = 0; i < (NodeListPtr->length); i++)
      {

            if (pIDOMNode) pIDOMNode->Release();            
            NodeListPtr->get_item(i, &pIDOMNode);


            if(pIDOMNode )
            {               

                pIDOMNode->get_nodeTypeString(&bstrNodeType);

                //We process only elements (nodes of "element" type): 
                BSTR temp = L"element";
               pIDOMNode->get_nodeTypeString(&bstrNodeType);

                //We process only elements (nodes of "element" type): 
                BSTR temp = L"element";

                if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)temp)==0) 
                {


                    pIDOMNode->get_nodeName(&bstrItemNode);                 
                    printf("Node: %ls\n", bstrItemNode);        


                    pIDOMNode->get_text(&bstrItemText);
                    printf("Text: %ls\n", bstrItemText);

numbers[(std::string)bstrItemNode] = (std::string)bstrItemText; // Here error.. need string..
有人能告诉我如何从这个类访问字符串来填充hashmap吗

错误是:

error C2440: 'type cast' : cannot convert from 'BSTR' to 'std::string'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1> : error C2440: 'type cast' : cannot convert from 'BSTR' to 'std::string'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous

请帮帮我,我卡住了。任何其他方式也会让你感激。谢谢…

您不能从BSTR转换为std::字符串。你必须这么做

作为一个旁注,BSTR的支持宽字符串,您可能需要考虑使用<代码> STD::WString ,而不是当前使用的窄字符串。另外,我建议使用

\bstr\t
而不是您在这里使用的纯
bstr
对象
\u bstr\u t
将为您管理内存,并使转换更容易(请参阅上面使用_bstr\u t进行转换的链接)。您仍然可以通过
GetAddress
GetBSTR
方法向方法传递一个_bstr\t,具体取决于您是否需要可修改的引用(有关示例,请参阅上的文档)

error C2440: 'type cast' : cannot convert from 'BSTR' to 'std::string'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1> : error C2440: 'type cast' : cannot convert from 'BSTR' to 'std::string'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous