1

I am trying to read an xml file into a ptree using read_xml function as below:

read_xml(myFile, myPtree, boost::property_tree::xml_parser::trim_whitespace);

Here myFile is an std::string and myPtree is a basic_ptree<std::string, std::wstring>.

It gives me the following error when building:

xml_parser_read_rapidxml.hpp(48): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Alloc>' (or there is no acceptable conversion)
         with
          [
              _Elem=char,
              _Traits=std::char_traits<char>,
              _Alloc=std::allocator<char>
          ]

Any pointers on what might be causing the error?

ashish g
  • 429
  • 1
  • 7
  • 16

1 Answers1

1

You could get messages as shown, simply because there is no implicit conversion from std::string to std::wstring

In that case, match the string types or try to adjust the basic_ptree specialization

Since you're parsing from XML, and the XML parser supports only one string type, it is likely that you need to make the key and data string types identical.

You could use the string type matching the XML parser, and use a translator_between<std::string, std::wstring> to invoke the appropriate character set conversion

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks, Looks like that is my problem. It can read the xml file only using a single datatype. So modifying my basic_ptree to have same datatypes for key and data fixes the issue. But I need to modify all my keys to be std::wstring now. Let me see how it goes. – ashish g Jan 10 '15 at 16:29