string key="hello";
Value v;
json_temp.AddMember(key.c_str(), v, json_temp.GetAllocator()); //compile error
json_temp.AddMember("hello", v, json_temp.GetAllocator()); //compile OK
how could I solve this problem?
You need to construct a temporary Value, creating a _copy_ of the string in case of a dynamic name:
Value n(key.c_str(), json_temp.GetAllocator());
json_temp.AddMember(n, v);
See also the example in the tutorial.
And what sense does it make that you have to create a temporary?
Most helpful comment
You need to construct a temporary
Value, creating a _copy_ of the string in case of a dynamic name:See also the example in the tutorial.