我有以下代码,但它无法编译。 我无法想出原因,请帮忙。
rapidjson::Document jsonDoc;
jsonDoc.SetObject();
rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator();
rapidjson::Value messageArr(rapidjson::kArrayType);
std::string test = std::string("TEST");
messageArr.PushBack(test.c_str(), allocator);
我遇到了以下错误:
错误:没有与调用‘rapidjson::GenericValue> ::PushBack(const char*,rapidjson::GenericDocument> ::AllocatorType&)’匹配的函数 messageArr.PushBack(test.c_str(),allocator);
const char *
包装器(如果超出范围将会崩溃)和/或短字符串* 15个字符或更少 - 或类似于此。由于您想要使用分配器,我假设您想要通过复制StrValue - 答案显示了如何实现。 - Adrian Colomitchi