简体   繁体   中英

c++ rapidjson addMember & rapidxml

When I use the function AddMember from the c++ library RapidJson and I use string as parameters

Everything Work fine

jsvalue.AddMember("Fare", "0", allocator);

but when I try to use a Function of RapidXml as parameter to get the node name, I get a fatal error

std::cout << "name : " << xmlnode_chd->name() << " value : " << xmlnode_chd->first_node()->value() << std::endl;
jsvalue.AddMember(std::string(xmlnode_chd->name()), std::string(xmlnode_chd->first_node()->value()), allocator);

xmlnode_chd->name() return a char*, that's why I cast it to string

This is the error message I get :

/home/otf/test/./include/xml2json.hpp|210|error: no matching function for call to 'rapidjson::GenericValue >::AddMember(std::string, std::string, rapidjson::GenericDocument >::AllocatorType&)'|

The rapidjson library's GenericValue::AddMember method does not contain an overload that accepts a std::basic_string as its first parameter. Your choices are GenericValue (which must be a string itself) or GenericStringRef. GenericStringRef can be constructed from a const char*, which is why your initial method worked, but cannot be constructed via a std::string directly. I recommend you rewrite your code to:

jsvalue.AddMember(xmlnode_chd->name(), xmlnode_chd->first_node()->value(), allocator);

BTW, you can find the documentation on this here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM