ashish g
ashish g

Reputation: 449

no operator found error with boost read_xml function

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?

Upvotes: 1

Views: 363

Answers (1)

sehe
sehe

Reputation: 393134

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

Upvotes: 1

Related Questions