Increase property tree value when converting to Unicode

Well, at first I am not a C ++ developer by nature; I managed to put something together and everything works fine, but I'm sure that in the eyes of an expert it looks like garbage =)

So, I have a free application that I created that uses the property tree in Boost libraries. I developed the whole application (in VS2010) with the setting Use Multi-Byte Character Set . I decided it was time to go through and update the Unicode-enabled application, as there are people with complex character sets that I would like to better support.

I went through the tedious process of changing all links and calls to use wide lines, all the necessary conversions. Nevertheless, at some point I completely stopped, only two compiler errors remained with me.

Both come from stream_translator.hpp (/ boost / property_tree /), lines 33 and 36 (as indicated below):

template <typename Ch, typename Traits, typename E, typename Enabler = void> struct customize_stream { static void insert(std::basic_ostream<Ch, Traits>& s, const E& e) { s << e; //line 33 } static void extract(std::basic_istream<Ch, Traits>& s, E& e) { s >> e; //line 36 if(!s.eof()) { s >> std::ws; } } }; 

Error on line 33:

 Error 347 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion) {...}\boost_1_49_0\boost\property_tree\stream_translator.hpp 33 1 

.. and error on line 36:

 Error 233 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion) {...}\boost_1_49_0\boost\property_tree\stream_translator.hpp 36 1 

From the fact that I was able to go back, it comes from stream_translator.hpp , ultimately starting with a call to get the value [for example. ptree.get ("some.path", "default value here")]

I really don’t know how to solve this problem and cannot find anything on the Internet to help me understand what the problem is. Any advice or information would be appreciated.

EDIT

So, I commented on everything related to ptree until it was compiled and then added them back. It turns out that I can call .get fine, this is get_child, where the error message @ line 36 appears (have not done another project yet, where is the wstring problem).

To simplify things, here is an effective call sequence that is good until get_child is called:

 boost::property_tree::ptree pt; boost::property_tree::read_xml("Config.xml", pt); int iAppSetting = pt.get("config.settings.AppSetting",1); //<- works fine ptree ptt; ptt = pt.get_child("config.Applications"); //<- adding this line causes the line 36 error 
+6
source share
1 answer

Guessing that your problem was the same as I came across ... There are extended versions of Boost.PropertyTree characters to support Unicode.

For Config.xml, which is configured as follows:

 <?xml version="1.0"?> <Zoo> <Monkey> <Food>Bananas</Food> </Monkey> </Zoo> 

Use the code syntax for this:

 // Load up the property tree for wide characters boost::property_tree::wptree pt; boost::property_tree::read_xml("Config.xml", pt); // Iterate BOOST_FOREACH(wptree::value_type const& v, pt.get_child(L"Zoo")) { if( v.first == L"Monkey" ) { wstring foodType = v.second.get<wstring>(L"Food"); } } 
+6
source

Source: https://habr.com/ru/post/915581/


All Articles