user2942945
user2942945

Reputation: 469

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&)’|

Upvotes: 1

Views: 1400

Answers (1)

Altainia
Altainia

Reputation: 1597

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

Upvotes: 2

Related Questions