Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:43+00:00 2026-06-01T12:24:43+00:00

I’ve used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I

  • 0

I’ve used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program.

Now I want to fill data in hashmap. But can’t able to do it. Error says conversion not possible to std::string from BSTR.

Here is part of code…

 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..

I tried following but it return only one character.

numbers[(char*)bstrItemNode] = (char*)bstrItemText; // return only 1 character..need whole string..

Can anyone tell me that how can I access string from this class to fill in the hashmap??

Error is:

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

Please help me, I’m stuck. Any alternative way also appreciate. Thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:24:44+00:00Added an answer on June 1, 2026 at 12:24 pm

    You can’t cast from a BSTR to a std::string. You have to convert it.

    As a side note, BSTR’s support wide character strings, you probably want to consider using std::wstring instead of the narrow string you are currently using. Also, I recommend using _bstr_t instead of the pure BSTR objects you are using here. _bstr_t will take care of managing the memory for you and make the conversions easier (see the above link that uses _bstr_t for the conversions). You can still pass a _bstr_t off to the methods via the GetAddress and GetBSTR methods depending on whether you need a modifiable reference or not (see the docs on _bstr_t for examples).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an XML file, the creators of it stuck in a bunch social
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.